Learn more with dummies

Enter your email to join our mailing list for FREE content right to your inbox. Easy!

View Controllers — the Main Storyboard Players

By Neal Goldstein, Dave Wilson

The storyboard of your iOS app is the white board, so to speak, on which you lay out the flow of the elements, or design pattern, of your application. This example application developed called RoadTrip uses the Model-View-Controller (MVC) design pattern, and in this particular design pattern, it’s the view controllers that implement the pattern’s controller component.


These controller objects contain the code that connects the app’s view objects to its model objects. Whenever the view needs to display something, the view controller goes out and gets what the view needs from the model.

Similarly, view controllers respond to controls in your Content view and may do things like tell the model to update its data (when the user adds or changes text in a text field, for example), compute something (the current value of, say, your U.S. dollars in British pounds), or change the view being displayed (like when the user presses the Detail Disclosure button on the iPod application to find out more about a song).

View controllers, as you can see in the figure, are the objects that control what is displayed and that respond to user actions. They are the heart and soul of the storyboard.


A view controller is often the (target) object that responds to the onscreen controls. The Target-Action mechanism is what enables the view controller to be aware of any changes in the view, which can then be transmitted to the model.

Imagine that an iPad user launches the RoadTrip app. On the left side (or in a popover), he or she sees a Table view and on the right side a Detail view (the Weather for example).


The user may tap an entry (cell) in the Table view to display events. The Events controller is then launched and sends a message to the appropriate method in the model to get the events. The model object returns a list of URLs, and so on. The controller then delivers that information to the view, which promptly displays the information to the user.

If your imaginary user now launches the RoadTrip app on the iPhone (or iPad Touch), the user will see a full-screen table view. The screen will shift to a detail view when the user taps a cell in the table. The same information is available in the iPhone version as in the iPad version, but the user interface has to be slightly different.

You will be pleased to know that you can build one set of Objective-C classes that works with both the iPhone and iPad storyboard files, so you only need one set of code to build your Universal app.

The sequence of events is as follows:

  1. A message is sent to that view’s view controller to handle the request.

  2. The view controller’s method interacts with the Trip model object.

  3. The model object processes the request from the user for the current events.

  4. The model object sends the data back to the view controller.

  5. The view controller sends the data to the view to display the information.