O'Reilly logo

Programming iOS 5, 2nd Edition by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 24. Web Views

A web view (UIWebView) is a UIView subclass that acts as a versatile renderer of text in various formats, including:

  • HTML
  • PDF
  • RTF, including .rtfd (which must be supplied in a zipped format, .rtfd.zip)
  • Microsoft Word (.doc), Excel (.xls), and PowerPoint (.ppt)
  • Pages, Numbers, and Keynote; before iWork 2009, these must be zipped (e.g., .key.zip), but starting with iWork 2009 they must not be zipped.

In addition to displaying rendered text, a web view is a web browser. This means that if you ask a web view to display HTML that makes reference to an object available on disk or over the Internet, such as an image to be shown as the source of an img tag, the web view by default will attempt to fetch it and display it. Similarly, if the user taps, within the web view, on a link that leads to content on disk or over the Internet that the web view can render, the web view by default will attempt to fetch that content and display it. Indeed, a web view is, in effect, a front end for WebKit, the same rendering engine used by Mobile Safari (and, for that matter, by Safari on Mac OS X). A web view can display non-HTML file formats such as PDF, RTF, and so on, precisely because WebKit can display them.

As the user taps links and displays web pages, the web view keeps back-and-forward lists, just like a web browser. Two properties, canGoBack and canGoForward, and two methods, goBack and goForward, let you interact with this list. Your interface could thus contain Back ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required