How to Add the Custom View Controller to Your iOS App to Set Up the Weather Controller

By Jesse Feiler

Although you may have a view controller for your iOS app defined in the storyboard, it’s a generic view controller and it’s clueless about what you want to display in a view, much less the model it will need to get the data from. You can create a custom controller that does know about its view and the model. Replace the generic controller with a custom one. Follow these steps:

  1. In the Project navigator, select the ViewController Classes group and then right-click and choose New File from the contextual menu that appears.

    Or choose File→New→File from the main menu (or press ⌘+N).

    Whatever method you choose, the New File dialog appears.

  2. In the left column of the New File dialog, select Cocoa Touch under the iOS heading, select the Objective-C class template in the top-right pane, and then click Next.

    You’ll see a dialog that will enable you to choose the options for your file.

  3. In the Class field of the dialog, enter WeatherController, choose or enter DetailViewController in the Subclass Of field, make sure that the Target for iPad check box is selected and that the With XIB for User Interface is deselected, and then click Next.

  4. In the Save sheet that appears, click Create.

    You’ve got yourself a new a custom view controller.