New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

iOS SDK and SQLite: Building Data-Driven Apps
Illustration by Don Barnett

Coding the web view


From:

iOS SDK and SQLite: Building Data-Driven Apps

with Bill Weinman

Video: Coding the web view

At this point, we have a working WebView, and it's being called from the Item View when the user selects an item. Now, let's fill in the details in the class. Let's make a working copy of our webView-01, and you can use your results from the last exercise, or I'm going to use the done version. You can do that too as well. I'll rename this webView-02 and open it in Xcode by double-clicking on the Xcode project file. And we're going to back out here to Finder and grab these methods in this methods.txt file.
Expand all | Collapse all
  1. 8m 29s
    1. Welcome
      57s
    2. Exercise files
      2m 17s
    3. Course overview
      3m 4s
    4. Application overview
      2m 11s
  2. 14m 49s
    1. Prototyping in a testbed
      1m 27s
    2. Building the view controller
      3m 45s
    3. Coding the testbed
      7m 56s
    4. Using the testbed
      1m 41s
  3. 37m 49s
    1. Understanding SQLite in iOS
      1m 41s
    2. Creating an Objective-C interface for SQLite
      9m 57s
    3. Testing the BWDB interface in the sandbox
      7m 1s
    4. Designing a database schema
      8m 7s
    5. Supporting the application with a specific interface
      7m 7s
    6. Using C pointers with automatic reference counting (ARC)
      3m 56s
  4. 21m 18s
    1. Understanding the table view
      1m 33s
    2. Creating the view controller
      6m 39s
    3. Reading from the database
      13m 6s
  5. 33m 50s
    1. Understanding the parsing process
      1m 57s
    2. Creating the item view controller
      12m 25s
    3. Reading data from the internet
      5m 30s
    4. Parsing the feed with NSXMLParser
      8m 2s
    5. Updating the item view with the feed items
      5m 56s
  6. 40m 14s
    1. Understanding the modal view
      1m 47s
    2. Constructing the view controller
      15m 5s
    3. Finding a feed link in a web page
      8m 55s
    4. Parsing the feed with NSXMLParser
      5m 4s
    5. Delegating back to the parent view
      6m 11s
    6. Deleting feeds
      3m 12s
  7. 21m 5s
    1. Creating the web view class
      12m 33s
    2. Coding the web view
      5m 25s
    3. Viewing pages in Safari
      3m 7s
  8. 14m 3s
    1. Understanding the iOS preferences system
      1m 23s
    2. Creating the preferences plist in Xcode
      7m 20s
    3. Reading preferences in your application
      5m 20s
  9. 6m 15s
    1. Adding pull-to-refresh functionality
      2m 34s
    2. Implementing the pull-to-refresh gesture for iOS 6
      3m 41s
  10. 27m 1s
    1. Understanding split view
      1m 4s
    2. Coding the table views
      11m 24s
    3. Implementing the iPad detail view
      6m 35s
    4. Implementing the iPad modal view
      7m 58s
  11. 35s
    1. Goodbye
      35s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
iOS SDK and SQLite: Building Data-Driven Apps
3h 45m Intermediate Jan 16, 2013

Viewers: in countries Watching now:

The iOS software development kit (SDK) includes the popular SQLite library, a lightweight yet powerful relational database engine that is easily embedded into an application. In this course, Bill Weinman teaches you how to build an RSS reader for iOS devices, integrating XML data and a streamlined interface. He explains how to use the SQLite database, display information in a table view, code view controllers, and create a preferences pane for your app. The resulting application is optimized for all iPhone and iPad displays.

Topics include:
  • Prototyping the app
  • Coding and working with a testbed
  • Creating an Objective-C interface for SQLite
  • Designing a database schema
  • Creating the view controllers
  • Reading and writing to the database
  • Parsing the RSS feed with NSXMLParser
  • Updating the item view with feed items
  • Implementing the pull to refresh gesture for iOS 6
  • Creating a universal application with multiple views
Subjects:
Developer Mobile Apps Databases
Software:
iOS
Author:
Bill Weinman

Coding the web view

At this point, we have a working WebView, and it's being called from the Item View when the user selects an item. Now, let's fill in the details in the class. Let's make a working copy of our webView-01, and you can use your results from the last exercise, or I'm going to use the done version. You can do that too as well. I'll rename this webView-02 and open it in Xcode by double-clicking on the Xcode project file. And we're going to back out here to Finder and grab these methods in this methods.txt file.

I'm just going to copy everything from right up there all the way down to the end of that section and come into Xcode and just place that down here before the end. And we can take a look at these. You'll notice the viewDidLoad has a little red exclamation point. That's because it's a duplicate. There was a stub already in here, so I'm just going to delete that stub and actually get rid of our little red bang there.

So, viewDidLoad is called the after the view is loaded and so it sets the title with the title from the feedItem, and it does some scaling and then it loads the request in the webView, and you notice it's using the webView property which in the .h file is actually an IBoutlet. So, that's already been hooked up in our storyboard. So, that will load the request, and it's going to want to call back the delegate methods, and we'll load those up here in a minute. ViewDidUnload, we just clear out our properties.

When view is loaded again later, that just prevents the same web page from showing up again, which probably won't happen anymore anyway. Some earlier versions of iOS, this was necessary. viewWillAppear, it sets the delegate for the webView to ourselves. And viewWillDisappear, it stops loading if the webView is still loading content, and it clears out the delegate. It also sets the networkActivityIndicator to off. Now, let's come back out here to TextWrangler and load up the WebViewDelegate methods.

When the webView starts loading, this gets called back, and we set our networkActivityIndicator to on, we also set the status of the our back button and forward button, whether they are enabled or disabled, to a property from the webView, which tells us whether or not it's possible to go backwards or forward. So, this makes our buttons work right, and I'll show you that one when we load this up. When it's done loading, we set the networkActivityIndicator to no, which turns it off, and we set the title in our title bar to this document title which we grabbed from JavaScript, from the webView.

So, whatever the document title is set to in the document itself, that will become the title. So initially, we loaded the title up here from our feedItem title, and now after the page is loaded, we update the title to whatever the document title is. And in the event there is an error, we have a little error document here which is just literal strings, which says that we had an error fetching the web page, and it fills it in with the localized description from the error object.

So, that's all really straightforward, and I'm going to save all of this, and we're going to go ahead and run it in the simulator. Make sure the iPhone Simulator is selected and press the Run button. Now, we'll just go ahead and load something from the lynda blog here. And you see, there is our networkActivityIndicator, and here is the document. You see, we have our reload button. If I press that, it reloads the page. There's our network activity spinner, and we have a stop button. So, if I start the reload and press stop right away, it stops it.

We have our action button, which still isn't hooked up. That will just display a log entry. And you notice these back and forward buttons. Those are grayed out. I can't actually press them. They're inactive but if I were to click on a link inside of here--there's our networkActivityIndicator-- we've brought up a new page. So, sometimes the back button doesn't light up, even though it's supposed to, and if you press the reload button, it makes it work. And this is just a bug in the webView. So now I can press this back button, and you see there's our networkActivityIndicator, and it's going back to the previous page.

And now, the forward button is lit up because that is now active, and it's now possible for that to work. So, if I press that, we'll go forward. I press that, we go back. So now, we have a working webview. Again, using the Cocoa Touch classes has made this very easy. Most RSS feed items point to a web page, so this solution makes it easier for us to display that rich data without a lot of coding. While our webView does display the content nicely and has a few useful features for navigation, it's not a full web browser.

So, we have a button for passing control of the content to Safari. When I press this button, of course right now all we got is this log entry. So, our remaining task is to implement that button.

Find answers to the most frequently asked questions about iOS SDK and SQLite: Building Data-Driven Apps.


Expand all | Collapse all
please wait ...
Q: Why is the RSSDB library in the exercise files different than the one in the videos?

A: The RSSDB library had to be updated to work around a bug in the iOS 7 SDK.

There is a bug in the iOS 7 SDK that prevents the BWDB fast enumeration implementation from working on a device. The symptom is code that runs fine on the emulator, but not on a device. iOS devices use an ARM processor, while the emulator runs on your Mac's Intel processor. This points to the LLVM ARM code generator as the source of the bug. Because the bug appears to be in the LLVM compiler, it may be some time before it is fixed.

As a workaround we have changed the getFeedIDs and getItemIDs methods in the RSSDB library so they don't use Objective C fast enumeration. 

Please note that this same bug also affects some of the BWDB testbed code in Chapter 2. The result is that it will run on the emulator but not on a device.

Q: After upgrading to Xcode 5.1 I get an error that says:

"Used type va_list (aka_builtin_va_list) where arithmetic or pointer type is required"

A: Please download the exercise files again to get the latest version of the BWDB library.
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed iOS SDK and SQLite: Building Data-Driven Apps.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Notes cannot be added for locked videos.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.