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

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Creating the item view controller

From: iOS SDK and SQLite: Building Data-Driven Apps

Video: Creating the item view controller

Before we can get the item data from the network for display, we need to create the table view for the item view controller. Let's start by making a working copy of the BWRSS-XML-start project. I'm going to Option drag this and rename it to BWRSS-XML-02. Now inside that folder, there is a file called BWRSS.xcodeproject, I'm going to double-click on that Xcode project file, and that will open the project in Xcode. We'll expand a couple of these disclosure triangles, so we can see our source code, and I want to select this BWRSS Group, which looks like a folder in its icon there.

Creating the item view controller

Before we can get the item data from the network for display, we need to create the table view for the item view controller. Let's start by making a working copy of the BWRSS-XML-start project. I'm going to Option drag this and rename it to BWRSS-XML-02. Now inside that folder, there is a file called BWRSS.xcodeproject, I'm going to double-click on that Xcode project file, and that will open the project in Xcode. We'll expand a couple of these disclosure triangles, so we can see our source code, and I want to select this BWRSS Group, which looks like a folder in its icon there.

And I'm going to create a new class file. We need to set up our Table View for the items so we do that by creating a class. I can either right click on this and say New File, or I can just come up here in the File menu and select New File. Under iOS and Cocoa Touch, select Objective-C class and press Next. Now, I going to name the class, BWRSSItemsTableViewController, and that's a subclass of UITableViewController. If UITableViewController is not selected there, you want to select it from this drop down box.

We're going to leave both of these items unchecked, we're not targeting for the iPad, and we're not using a NIB File. And I'll select Next and the default location here is in this BWRSS folder, which corresponds to this BWRSS Group over here. We want to make sure that the BWRSS Group is selected, and that it's targeted for the BWRSS Application. So we select Create, and there we now have our class files. I'm just going to drag them up here so that they're in with the other class files.

Now we're going to open the Storyboard and create a segue for our new Table View. So, I'm just going to open this up a little bit, so we can see the storyboard_file name_iPhone_storyboard, and because I have such limited real estate here on the screen, I'm going to zoom out a little bit. You probably won't need to do that, and there's a lot of things that don't work right when it's zoomed out. So don't, if you don't need to. Then here, make sure that the Utilities Pane is selected, and under Objects here, I'm going to grab the Table View Controller, and I'm just going to drop it right about there and then I can adjust it so that it aligns properly. It's not necessary, but it's a good idea.

Now I'm going to zoom back in here, and I'm going to create as segue. So I created a segue by control dragging from one object that can be selected to our New Table View. So, over here you see we have the Feeds Table View. If I scroll down you can see that it's Feeds Table View Controller. And I'm going to Control-click on the Table Cell here and drag over towards the New Table View, and you see that I get this little line, and when I let go of the mouse button, I get this Select a Segue, and I select the Push type of segue, and it creates this segue.

So this here is the segue, and if I click on that, then I can actually edit it. Let me select over here the Attributes Inspector, and I can give the segue an identifier. So, I'm going to call this Segue, SegueToItemsTableView. I am going to press the Return key, because that actually makes this take effect, sometimes it doesn't happen if you type something into a field in Xcode, and you don't press the Return key. So, now our segue is named, and you see its Style is Push, and so we've created the segue.

There are just a couple more of things we want to do to our New Table View. You'll notice down here it says Table View Controller, and so if I select this, and I select this orange circle here, which is the Actual View Controller, and come back over here to the Identity Inspector, you notice that its class is UITableViewController. We want our new sub-class to be the Class for this table view. So if I select this BWRSSItemsTableViewController, you'll notice that now, it says Items Table View Controller. If I select a different controller over here, it will say Items Table View Controller, and that's what you want it to say.

And that way it will be actually be using the code in our BWRSSItemsTableViewController.m and .h file. So you notice that this is grayed out over here a little bit, this icon for our storyboard. I'm going to press Command+S on my keyboard, and that will take that gray away and make it white, to indicate that it's saved. I tend to press the Command+S key a lot, sometimes I might forget to say that I'm doing that. But it's an important habit to get into. Now I'm going to select our Table Cell, and if I come back over here to the Attributes Inspector, under Style I'm going to select Subtitle, make sure that the Accessory says None, and then the reuse Identifier, I am going to type in itemsCell, like that and press the Return key.

You notice over here in our Feeds Table View that the cell has this little disclosure indicator. We actually don't need that. So I'm going to select that, under Accessory in the same pane, I'm going to select None, and you see that that goes away. So now, we're all set up. I am going to press Command+S to Save and come back over here to our ItemsTableViewController.h file, and the first thing I'm going to do in this .h file is I'm going to import our database header. So I'm going to come up here and type #import, and I am going to type RSSDB.h, see I got my code completion there, and Command+S to Save.

Now, when I come back out here to Finder, and you'll notice we've got a few text files here in our Exercise Files folder in the Chapter04 folder. That's because Objective-C tends to be pretty verbose, and we don't want to have to type all this stuff. So I am going to open this header, this is 02-header.text file. In my text editor--I'm using TextWrangler, you can use any text editor as long as it's a plain text editor, a coding text editor and not a Word Processor. I'm going to select these three lines here, press Command+C to Copy, and come back over here into Xcode, and I'm going to just select this one line, here on line 12 and press Command+V.

Now, we have our interface property, property, and end, and that's the way that that should look. Now, press Command+S to Save. Let's go ahead and close our Utilities pane, so this all fits on my little screen here. You can leave that open on yours. I just have limited screen real estate here. We can see that our class is called BWRSSItemsTableViewController. It's a subclass of UITableViewController, and it implements the NSXMLParserDelegate protocol.

We have two properties declared, rssDB and currentFeedID, and those are populated actually from the FeedsTableViewController. We'll see that in a little bit. So, this header file is now complete. I'm going to press Command+S to Save, and we're going to open up the .m file for the ItemsTableViewController. As I scroll down here, you'll notice a couple of these orange lines here, these are warnings. We can just remove this safely. We'll be editing these methods later on in this chapter, but I'm just going to remove the warnings for now. Press Command+S to Save.

I'm going to come back out here to the Finder, and I'm going to open this text file here, -02-methods. This will open up in my text editor, and you see we have quite a few things in here. The first thing we're going to do is select these class extension for private members lines, and I'm going to press Command+C to Copy. And come back over here into Xcode, and I'm just going to select this line right here, which is our interface declaration for a class. And I'm going to press Command+V, and we'll replace that line with what we've copied and pasted from our text file.

So, we have a few variables here that are being used as private members for our class, and we'll talk more about each of them later on. Going back over here to our text editor, I've got some data properties, and again, these are private variables inside our class. I'm going to copy all of those, and I'm going to paste those in right here, and press Command+S to Save. Finally, down here we have this viewWillAppear method.

I'm going to copy that, and I'm going to paste that in right here. Press Command+S to Save. So you notice here in this code, one thing that we do is we check the currentDevice userInterfaceIdiom to see if we're running on an iPad. If we are, we set this private member variable iPadIdiom = YES, and you can see up here in our class extension, we have this BOOL iPadIdiom. So, we can test that later on in the code to see if we're running on an iPad.

One other thing you'll notice here, I'm using this rssDB property and also this feedRecord property. These are populated from the FeedsTableViewController, and we'll get to that in a moment, and we're using that to actually find the current record for this view. So, we select a row on the FeedsViewController, it will bring this ItemsViewController already populated with the items in that feed, and this is how that's done. So, if we go over here into the FeedsTableViewController--make sure this is saved, I'm pressing Command+S again--and we come over here into the FeedsTableViewController, and we select this prepareForSegue. You notice that this is not populated yet.

Come back out here into Finder and open this FeedsTableViewController-02-Support.txt in our text editor and here's our segue delegate for that file. So, I'm going to copy and paste that into Xcode. Just select this entire method here and press Command+V, and we haven't yet imported this header file, so we're getting a couple of errors. We'll take care of that in a moment. You'll notice that this gets called when a segue happens from this view controller.

This is the FeedsTableViewController, and it gets passed this segue object, and that segue object has a destinationViewController, and so I can assign that destinationViewController to a BWItemsTableViewController class object and then I can actually populate ItemsTableViewController.currentFeedID and ItemsTableViewController.rssDB. So if I come up here to the top then I'm just going to import our header file BWRSSItemsTableViewController.h.

Now, when I come back down here to the prepareForSegue, you see those errors have gone away, and we are now assigning our FeedID and our rssDB to the properties in the ItemsTableViewController. I press Command+S to Save this, and we see over in our ItemsTableViewController in ViewWillAppear, this is where we're using those variables. We are also over here setting our row height so that we have enough height to display the things that we want to display. Now, I can just build this.

I'm going to press Command+B to Build. Before I run in the simulator, I want to make sure I've got the iPhone simulator and not the iPad simulator selected, and then I can just press Run, and this will run it in the simulator. There we are. This is the 4-inch Retina iPhone simulator, and this is scaled down because this screen is so small. It doesn't have enough pixels to actually support that. Hopefully you're running on a bigger screen. So, this doesn't have any borders. It doesn't have a Home button, but this is the iPhone simulator. Yours will probably look different, and when I select one of these feeds here, you see it brings up our new ItemsTableViewController, and you can see there's the title that gets populated right here, self.title = self.feedRecord (@"title"), so it's actually reading that from the database based on the current feedID that got passed from the FeedsTableViewController. So, there it is.

That is completely working. I can bring up the lynda blog. Of course, none of these are being populated yet. That will happen in one of our later movies, but we now have a working table view for the items. We're using the segue from the storyboard to set up the ItemsTableView, and now we are ready to fill in the ItemsTableView with some data, and we'll do that in the next lesson.

Show transcript

This video is part of

Image for iOS SDK and SQLite: Building Data-Driven Apps
iOS SDK and SQLite: Building Data-Driven Apps

41 video lessons · 6326 viewers

Bill Weinman
Author

 
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

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

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.