Angry Rage Monkey

A blog by Jock Murphy

UIWebView is not always the answer…

Note: This is going to be a rather technical post, so apologies to the non programmers amongst you.

When it comes to drawing things on the screen in an iOS (those devices that include the iPhone, the iPad, and the iPod touch), it seems over and over again the answer you find is:

Use a UIWebView

Want to display some rich text on the screen? Use a web view.  Want to show a PDF? Use a web view.  Want to draw a SVG image on the screen? Use a web view.

The last example is especially egregious.  Because what the so called “Experts” are saying is that every time you want to display a illustrated image on the screen, you should create a mini web browser and put it on the screen.

This approach has its places.  I mean, if you want to display some help text, then yes a web view is a great way to do that.  It even makes sense for displaying a PDF to the user — though using Quick Look may be a better answer.  But just for a rich text label? That is insanity.  The web view is not a lightweight component.  You should put multiple of them on the screen just because you are too lazy to figure out another way.

And there are other ways, as it turns out.  But the “Experts” — and by that I mean the people who are most active in answering posts on places like CocoaDevStack Overflow, and the like.  Just like in Swing components can take HTML to represent rich text.  This is not the same thing (and not as heavyweight) as embedding a web view.  There is also a whole framework in Cocoa called Core Text, just for rendering rich text on the screen.

But far to many of these experts (enough with the sarcastic quotes) found the hammer that is the web view, and make all their problems look like nails.  It also means that for genuine issues that don’t have easy solutions (like rendering SVG), have aren’t going out and making nice open source libraries to do just those things.

Odd are that someone is going to email me a link to just that thing, and I and I want to make it perfectly clear that it doesn’t disprove my point.

Cocoa and Cocoa touch are amazing application frameworks (though hampered by a language that was the height of what 1985 had to offer), but they are far from perfect.  Nothing is after all.  When you run into one of those odd places where it lets us down, we shouldn’t just grab the hammer, we should make sure we are using the right tool for the job.  And when that tool can’t be found, we should make it, and share it with our peers.

I am far from a Cocoa Expert (though I get the job done), but even I know that. 

So the next person who suggests using a UIWebView to display anything other than a HTML document, is going to get hit across the face with a brining haddock.  

Why? The brine makes it sting more…