Graphics Programs Reference
In-Depth Information
the DetailViewController is destroyed. The next time a row is tapped, a new in-
stance of DetailViewController is created.
Having a view controller push the next view controller is a common pattern. The root
view controller typically creates the next view controller, and the next view controller cre-
ates the one after that, and so on. Some applications may have view controllers that can
push different view controllers depending on user input. For example, the Photos pushes a
video view controller or an image view controller onto the navigation stack depending on
what type of media was selected.
(The iPad-only class UISplitViewController calls for a different pattern. The
iPad's larger screen size allows two view controllers in a drill-down interface to appear on
screen simultaneously instead of being pushed onto the same stack. You'll learn more
about UISplitViewController in Chapter 26 . )
Passing data between view controllers
Of course, the UITextField s on the screen are currently empty. To fill these fields, you
need a way to pass the selected BNRItem from the ItemsViewController to the
DetailViewController .
To pull this off, you will give DetailViewController a property to hold a
BNRItem . When a row is tapped, ItemsViewController will give the correspond-
ing BNRItem to the instance of DetailViewController that is being pushed onto
the stack. The DetailViewController will populate its text fields with the proper-
ties of that BNRItem . Editing the text in the UITextField s on DetailViewCon-
troller 's view will change the properties of that BNRItem .
In DetailViewController.h , add this property. Also, at the top of this file, forward
declare BNRItem .
#import <UIKit/UIKit.h>
@class BNRItem;
@interface DetailViewController : UIViewController
{
__weak IBOutlet UITextField *nameField;
__weak IBOutlet UITextField *serialNumberField;
__weak IBOutlet UITextField *valueField;
__weak IBOutlet UILabel *dateLabel;
}
@property (nonatomic, strong) BNRItem *item;
Search WWH ::




Custom Search