Join Bill Weinman for an in-depth discussion in this video Creating the item view controller, part of iOS SDK and SQLite: Building Data-Driven Apps.
- In order to display items from a feed, we'll need to set up a new Table View Controller. Here I have opened a working copy of BWRSS-Items-01 from chapter four of the Exercise Files. The results of this lesson can be found in BWRSS-Items-02 in the same chapter. So the first thing we're going to do is we're going to create a new file. I'm gonna come down here and press the plus button here and select File. And this would be a Cocoa Touch Class.
And again, this is gonna be based on the UITableViewController and it's going to be called ItemsViewController and we'll be in Swift. We don't need a XIB file. And we'll go ahead and save it in the same folder, same group and we want to make sure our target is checked. And just for now, we're gonna go ahead and put in our title. So we know that this is being called when we set up the storyboard.
We call this Items and press Command S to save. And so that goes in the viewDidLoad right there. I'm gonna select the storyboard. And now, you'll notice here I'm just gonna zoom out so we can see this. We have our Split View Controller and then on the top we have our Master View with a Navigation Controller and a Table View. And that there is our Feeds View Controller. And then, you notice there's another segue here and it's actually connected to the Cell in the Table View Controller.
And that connects in to this Navigation Controller and the Detail View Controller on the detail side of the Split View. What we wanna do is we wanna actually insert a new Table View right over here and have this segue connected to that Table View instead of this one. And so we're gonna do that like this. First, I'm gonna zoom back in because this just doesn't work if you're zoomed out. Show the Object Library.
And we want a Table View Controller and I'm just gonna drag that over here. And then I need to move it around so I'm gonna zoom out again and get it to where I want it to be. And you notice it says Module, None. That happens sometimes, although it has the ItemsViewController appear. This is a bug in the current Xcode so you may or may not see all your classes up here. You may have to type BWRSS in here and you may need to actually even type the name of your Class up here.
But that is now an ItemsViewController. And if we come over here to the Attributes and select the Cell, again I need to zoom in or it won't let me select it. And under Style, we want it to be Subtitle. We also want to enter the Reuse Identifier, the Cell Identifier And this will be ItemCell, and press the Enter key there so it is. And we want a new segue and the segue will come from the Cell in the Master View Controller which is actually our FeedsViewController.
But still says Master over here even though on this one it says Items View Controller. These are just little things that they need to work out in Xcode. And so I'm gonna hold down my Control key and drag from this Prototype Cell over to the new Table View Controller and that will give me a segue. And my segue style is going to be show and then I select the segue itself here and come over the Attributes Inspector and type in an Identifier and this is the ItemsSegue.
Now you notice that we no longer have a connection down here. We can take care of that a little bit later. For now, I'm just going to press Command S here and we'll go ahead and build and run. Command S, saves, so I'm gonna build and run with Command R. And you'll notice when I click on any one of these, I get my new Items View Controller. It says Items up there. So the results after I've completed these steps can be found in BWRSS-Items-02 in chapter four, the Exercise Files. Now we have our Items View Controller.
So we're ready to populate it with data and there are three major steps for this. First, we need to read the RSS feed from a web server. Then we need to parse the RSS feed. And finally, we need to populate the Table View. We'll be taking care of these tasks in the next lessons in the rest of this chapter.
- Building a testbed
- Creating an Objective-C interface for SQLite
- Creating a CRUD interface
- Designing the database schema
- Creating the main table view
- Creating the items table view
- Adding new feeds
- Parsing feeds with NSXML Parser
- Viewing webpages
- Preparing icons and toolbar images
- Adding a preferences pane
- Including pull-to-refresh and other features