Video: Implementing the iPad detail view

Now that we have the feed and item views running, it's time to implement the Web view. For the iPad version, we're using the Detail View controller for the Web view. Let's make a working copy of BWRSS-splitview-02. I'm going to use the done version here. You can use what you completed in the last movie if you like. I'm going to call this BWRSS-splitview-03, and I'm going to open it in Xcode by double-clicking on this Xcode project file.

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.

Implementing the iPad detail view

Now that we have the feed and item views running, it's time to implement the Web view.For the iPad version, we're using the Detail View controller for the Web view.Let's make a working copy of BWRSS-splitview-02. I'm going to use the done version here.You can use what you completed in the last movie if you like.I'm going to call this BWRSS-splitview-03, and I'm going to open it in Xcode by double-clickingon this Xcode project file.

Now, here in our BWRSSDetailViewController--I'm going to expand this a little bit so we can see that--see that we have our local instance variables and properties here, and we have just threelittle methods inside of this implementation. I'm actually going to delete all of that.And then I'm going to come back out here to the Finder, and here, we have our detailview-03-methods.txtfile and grab that, and I'm just going to select the whole thing.You can see there's a lot of typing here, and we'll go through it, and I'll explain in a little bit.

I'm going to select all of that and press Command+C to copy and come in here to Xcode,and right there with the cursor just before the end marker, I'm going to press Command+Vto paste it all in there.So, there are a few interesting things going on here.You'll notice in this section called set up the view when called, there's a methodcalled setDetailItem, and this is an Objective-C convention.When you have a property called detailItem-- you see it's a property with the @property--the compiler will create a setDetailItem and getDetailItem methods.

And here, I'm overwriting that setDetailItem method, so when another object assigns somethingto that variable, to that property, the setDetailItem gets called.And by overloading it, it allows me to do some other things during the process of setting that value.So here I just set the value at the top, and then I call configureView which is this methodabove there, and I dismiss the pop-over if there is one.And so, what I know is that when that variable is getting set, somebody has tapped on somethingbecause it's in that Items View Controller, and we'll set this up in a moment where thatproperty is getting set, and so that's where this is being called.

So that allows me to intercept that action.So it calls configureView which then sets up our NSURLRequest and calls the webView with that URL.So, the URL is getting passed in this newDetailItem, and that's getting assigned to feedItem uphere, and feedItem is being used to load the webView.Then down here, we have some what I call split view support.When the left view is hidden, that means that we're in Portrait mode.

We grab our button bar, and we add a button to it on the left, and we use that to controlthe popoverController.When the left view is shown again, we undo that.This is the setPopoverButton and clearPopoverButton methods that are being called by those.So, I'm going to press Command+S here, and I'm going to come back out to TextWrangler,and I'm going to close that, and come out to finder, and I'm going to load up our ItemsTableViewController-03-methods,and there's really just a couple of things in here.

So we'll come back over to Xcode, and we'll select our ItemsTableViewController.m file.First thing I want to do is I want to grab this import, copy and paste.And that's for our DetailViewController because we're going to be setting a property on that object.We'll come back out here. And here's our didSelectRowAtIndexPath.This is what gets called when you touch a row on a table, and that's selecting it.And if I come up here, we can find that, there it is didSelectRowAtIndexPath.

I'm just going to take this whole method, and I'm going to select the whole thing andpress Command+V to paste in what we've copied out of that text file, and Command+S to save.So, this is really simple, if (haveSplitViewController), and we set that up above in either viewDidLoad or viewWillAppear.Here it is, viewWillAppear.If we have a SplitViewController, then we have a SplitViewController.We're setting that flag.

And that flag is declared up here as a BOOL in our private members.So if we have a SplitViewController, that means that we're on an iPad.Now, I could have tested it for the iPad idiom.But really, what I'm concerned with here is do we have a SplitViewController?Because if we're on an iPad, and we don't have a SplitViewController for some reason, then this is moot.So, if we have a SplitViewController, then we go ahead and we get the DetailViewController,and we get the WebViewController from our viewControllers array.

And in our WebViewController, we assign to this detailed item, and you remember, that'sgoing to call our setDetailItem method that we looked at a few minutes ago.We're going to pass it that itemRecord, and that will make everything work.So now I'm going to save this, and we select our iPad Simulator.We're going to go ahead and run it. So now we're in Portrait mode.I'm going to press Command+Left Arrow, and that will put us in Landscape mode.And now we have our master control over here, our table views.And over on the right, we have our detailController.

And so, if I select one of these, and I select one of these, you see our little spinner runningup there, and there's our web page and our WebView and our DetailViewController.Now, here's the interesting thing.If I go ahead and just select a different item here, you notice we get a different page,and now this Back button is lit up.So I can press that and get back to the previous page.Unlike the iPhone form factor, this webView is in a separate pane here, and so it's visible all the time.So there is no reason to clear it out anymore.

If I come over here, and I load up something from the lynda blog, there it is, I can goback to the previous page that I was at.So these Back and Forward buttons, they're active more often than they are in the iPhone form factor.Now the webView is working and so the app is mostly functional.It's really a straightforward process when you know the ins and outs of it.Subclassing the existing webView makes it especially easy.The next step is to implement the AddView modal dialog box, and then we'll be done.

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

Here are the FAQs that matched your search "" :

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.

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.

Already a member ?

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

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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:

new course releases

newsletter

general communications

special notices

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:

new course releases

newsletter

general communications

special notices

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