Changes

An iPhone OS Core Data Tutorial

1,880 bytes added, 20:33, 2 August 2010
Adding a View Controller
@end
</pre>
 
Once the changes have been made, be sure to save both files before proceeding. Failure to save the changes at this point will likely cause problems in later steps.
 
== Connecting the View ==
 
The next step is to add the new view controller to the project, associated with the view NIB file and connect it to the application delegate.
 
Select the ''coreData'' entry from the top of the ''Groups & Files'' list to display all the files in the project and scroll down to ''MainWindow.xib''. Double click on this file to load it into the Interface Builder tool. From the ''Library'' window, drag and drop a ''View Controller'' object onto the ''MainWindow.xib'' window. Once released, the new view controller should appear beneath the existing objects as illustrated in the following figure:
 
 
[[Image:core_data_mainwindow.jpg]]
 
 
With the new view controller selected, open the Identity Inspector window (''Tools -> Identity Inspector'' or Command + 4) and change the ''Class'' value to ''coreDataViewController'':
 
 
[[Image:iphone_core_data_view_class.jpg]]
 
Display the Attributes page by selecting the far left toolbar button in the inspector window and assign ''coreDataViewController''as the NIB file:
 
 
[[Image:iphone_core_data_view_nib_file.jpg]]
 
 
Finally, establish a connection between the application delegate and the view controller. This is achieved by clicking on the ''core Data App Delegate'' item in the ''MainWindow.xib'' window, dragging the resulting blue line to ''Core Data View Controller'' item in the same window and selecting ''viewController'' from the menu. With the ''Core Data View Controller'' item selected in the ''MainWindow.xib'' file and the Connections Inspector displayed, the settings should appear as shown in the following figure:
 
 
[[Image:iphone_core_data_app_delegate_connections.jpg]]
 
 
Save the file and exit from Interface Builder.
Now that we have a view controller programmed into our application we need to extend that class to include some actions and outlets.