Cover by Alasdair Allan

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Adding a City View

You might have a nice navigation bar, but it doesn’t do any navigation yet, and after backing out of the changes you made to the tableView:didSelectRowAtIndexPath: method to present a pop up, the code doesn’t tell you about the selected city anymore. Let’s fix that now and implement a view controller and associated view to present the city information to the application user.

Right-click on the Classes folder in the Groups & Files pane and select AddNew File. Choose a UIViewController subclass and tick the checkbox to ask Xcode to generate an associated NIB file, as shown in Figure 5-17. When prompted, name the new class CityController.m, as this will be the view controller we’re going to use to present the information about our cities.

Select a UIViewController subclass and tick the checkbox for Xcode to create an associated XIB for the user interface

Figure 5-17. Select a UIViewController subclass and tick the checkbox for Xcode to create an associated XIB for the user interface

This will generate three new files: CityController.h, CityController.m, and CityController.xib. For neatness you might want to drag the CityController.xib file into the Resources folder of the project along with the other project NIB files.

Right now, the new NIB file is just a blank view. We’ll fix that later, but first we need to add code to the tableView:didSelectRowAtIndexPath: method in the RootController.m class to open the new view when a city is selected in the table view:

- (void)tableView:(UITableView ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required