Goal: Add the user interface to the customer detail view and specify the outlets in the DetailController.m and DetailController.h files.
#import <UIKit/UIKit.h> #import "SUP101_Customer.h" @interface DetailController : UIViewController { IBOutlet UITextField *fname; IBOutlet UITextField *lname; IBOutlet UITextField *phone; SUP101_Customer * originalObj; } @property (nonatomic, retain) UITextField *fname; @property (nonatomic, retain) UITextField *lname; @property (nonatomic, retain) UITextField *phone; @property (nonatomic, retain) SUP101_Customer *originalObj; - (SUP101_Customer *)originalObj; - (void)setOriginalObj: (SUP101_Customer *)newObj; -(IBAction)buttonPressed:(id)sender; @end
#import "DetailController.h" #import "SUP101_SUP101DB.h" #import "SUP101AppDelegate.h" @implementation DetailController @synthesize fname; @synthesize lname; @synthesize phone; - (SUP101_Customer *)originalObj { return originalObj; } - (void)setOriginalObj: (SUP101_Customer *)newObj { if (originalObj != newObj) { [originalObj release]; originalObj = [newObj retain]; } } // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } - (IBAction)buttonPressed:(id)sender { if (([lname.text compare:originalObj.fname] != NSOrderedSame) || ([fname.text compare:originalObj.lname] != NSOrderedSame) || ([phone.text compare:originalObj.phone] != NSOrderedSame)) { SUP101_Customer *newCustomer = [SUP101_Customer find:[originalObj id]]; if (newCustomer) { newCustomer.lname = lname.text; newCustomer.fname = fname.text; newCustomer.phone = phone.text; [newCustomer save]; [newCustomer submitPending]; while ([SUP101_SUP101DB hasPendingOperations]) { sleep(1); } SUP101AppDelegate *delegate = [[UIApplication sharedApplication] delegate]; [delegate.navController popViewControllerAnimated:YES]; } } } /* // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } */ // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)viewWillAppear:(BOOL)animated { fname.text = originalObj.fname; lname.text = originalObj.lname; phone.text = originalObj.phone; [super viewWillAppear:animated]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [fname release]; [lname release]; [phone release]; [originalObj release]; [super dealloc]; - (IBAction)touchedEnded:(NSSet*)touches withEvent:(UIEvent*)event { UITextView* fname1 = (UITextView*) [[self view] viewWithTag:1]; UITextView* lname1 = (UITextView*) [[self view] viewWithTag:2]; UITextView* phone1 = (UITextView*) [[self view] viewWithTag:3]; [fname1 resignFirstResponder]; [lname1 resignFirstResponder]; [phone1 resignFirstResponder]; } @end