ADDINGA MODELOBJECT 18
Start Xcode, and create a new navigation-based application that does
not use Core Data for storage. Name the project DailyShoot.
By the way, you may have noticed some important differences in the
templates you have available. The Split V i e w - b a s e d Application tem-
plate is new and can be used only for iPad-based projects. The Navi-
gation-based Application and Utility Application templates can be used
only for new iPhone projects. The W i n d o w - b a s e d template can create
an iPhone project, an iPad project, or a universal project that targets
both platforms at once. The remaining templates can be used as the
starting point for either iPhone or iPad projects, but you have to specify
which using a drop-down.
W e ’ r e not going to do anything with the app delegate or with the Main-
Window nib. If this were a production app, we would take the time to
change the name of the RootViewController class and the corresponding
nib to something that has more meaning in the current setting. Because
it’s easy to make an error while making these changes and because the
changes have nothing to do with what we’re working on in this chapter,
we’ll leave the names as they are.
1.4 Adding a Model Object
A table view needs a data source that can answer three basic questions:
• How many sections are in the table?
• For each section, how many rows are in this section?
• For each row, what goes in this row?
In the project created for us from the template, the RootViewController is
the table view’s data source. W e ’ r e going to add a model object to our
project. This is the classic Model V i e w Controller (MVC) decoupling. The
view talks to the controller and the controller talks to the model.
UITableView RootViewController Assignments
tableView:
numberOfRowsInSection:
count:
The table view sends the message tableView:numberOfRowsInSection: to
the controller. The controller in turn sends the message count to the
Assignments object, our model object. The model object responds to the
Report erratum
this copy is (P1.0 printing, September 2010)
Download from Wow! eBook <www.wowebook.com>