Datasheet

768
Entering and Saving the Hotel Information
You can now also uncomment out the delegate assignment, because you’ll
implement all of that next:
addHotelController.delegate = self;
Adding the delegation plumbing
The final step is to add all the code necessary to implement delegation
You’ll start by adding the code in bold in Listing 1-15 in order to add the pro-
tocol (you’ll name it AddHotelControllerDelegate) and other required
declarations to AddHotelController.h.
Listing 1-15: AddHotelController.h
#import <UIKit/UIKit.h>
@class Trip;
@class Hotel;
@protocol AddHotelControllerDelegate;
@interface AddHotelController : UIViewController
<UITextFieldDelegate> {
id <AddHotelControllerDelegate> delegate;
Trip *trip;
Hotel *hotel;
IBOutlet UITextField *street;
IBOutlet UITextField *state;
IBOutlet UITextField *zip;
IBOutlet UITextField *name;
IBOutlet UITextField *city;
}
- (id) initWithHotel:(Hotel*) theHotel trip:(Trip*) theTrip;
- (IBAction) getFromContacts: (id) sender;
- (IBAction) saveToContacts: (id) sender;
@property (nonatomic, assign)
id <AddHotelControllerDelegate> delegate;
@end
@protocol AddHotelControllerDelegate
- (void)addHotelController:(AddHotelController *)controller
didFinishWithSave:(BOOL)save;
@end
Both the delegate instance variable and its corresponding property may look
a bit odd to you.
id <AddHotelControllerDelegate> delegate;
@property (nonatomic, assign)
id <AddHotelControllerDelegate> delegate;
41_542934-bk07ch01.indd 76841_542934-bk07ch01.indd 768 3/23/10 11:01 PM3/23/10 11:01 PM