// // PersonDetail.m // TouchEdLightly // // Created by Andrew Kinnie on 5/16/10. // Copyright 2010 WONOVA. All rights reserved. // #import "PersonDetail.h" @implementation PersonDetail @synthesize firstNameField, lastNameField, createdLabel, updatedLabel, person, scrollView, personIdLabel; /* // 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; } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; scrollView.contentSize = self.view.frame.size; } /* // 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 { [super viewWillAppear:animated]; if(person.personId) { self.title = [NSString stringWithFormat:@"Edit %@ ID %@", [person fullName], person.personId, nil]; } else { self.title = @"Add Person"; } firstNameField.text = person.firstName; lastNameField.text = person.lastName; createdLabel.text = [person.createdAt description]; updatedLabel.text = [person.updatedAt description]; NSLog(@"personId is %@", person.personId); personIdLabel.text = [person.personId description]; self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save:)] autorelease]; } //- (void)viewWillDisappear:(BOOL)animated { // [[NSNotificationCenter defaultCenter] removeObserver:self]; //} - (void)keyboardDidShow:(NSNotification *)notification { if(keyboardVisible){ NSLog(@"keyboard already visible. Ignore notification."); return; } //NSLog(@"resizing"); NSDictionary *info = [notification userInfo]; NSValue *value = [info objectForKey:UIKeyboardBoundsUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; CGRect viewFrame = self.view.frame; viewFrame.size.height -= keyboardSize.height; scrollView.frame = viewFrame; keyboardVisible = YES; } - (void)keyboardDidHide:(NSNotification *)notification { if(keyboardVisible){ NSLog(@"keyboard already hidden. Ignore notification."); return; } //NSLog(@"resizing"); NSDictionary *info = [notification userInfo]; NSValue *value = [info objectForKey:UIKeyboardBoundsUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; CGRect viewFrame = self.view.frame; viewFrame.size.height += keyboardSize.height; scrollView.frame = viewFrame; keyboardVisible = NO; } - (IBAction) save: (id) sender { if (self.person != nil) { person.firstName = firstNameField.text; person.lastName = lastNameField.text; NSDate *now = [NSDate date]; person.updatedAt = now; [person saveRemote]; } [self.navigationController popViewControllerAnimated:YES]; } - (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 { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [scrollView release]; [person release]; [firstNameField release]; [lastNameField release]; [createdLabel release]; [updatedLabel release]; [personIdLabel release]; [super dealloc]; } @end