// // RootViewController.m // TouchEdLightly // // Created by David Avendasora on 4/23/10. // Copyright WO-NoVA 2010. All rights reserved. // #import "RootViewController.h" #import "AddPersonController.h" #import "Person.h" #import "PersonDetail.h" @implementation RootViewController @synthesize addButton, people, tableView; #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.people = [Person findAllRemote]; self.navigationItem.rightBarButtonItem = self.addButton; self.navigationItem.leftBarButtonItem = self.editButtonItem; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.people = [Person findAllRemote]; [self.tableView reloadData]; } -(IBAction) refreshButtonAction:(id)sender { self.people = [Person findAllRemote]; [self.tableView reloadData]; } /* - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } */ /* - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } */ /* - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } */ /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations. return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ #pragma mark - #pragma mark Table view data source // Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.people count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. cell.textLabel.text = [[self.people objectAtIndex:indexPath.row] fullName]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ // Override to support editing the table view. - (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { [aTableView beginUpdates]; if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source. [aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [(Person *)[people objectAtIndex:indexPath.row] destroyRemote]; [people removeObjectAtIndex:indexPath.row]; } [aTableView endUpdates]; } /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ #pragma mark - #pragma mark Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { PersonDetail *detailViewController = [[PersonDetail alloc] initWithNibName:@"PersonDetail" bundle:nil]; Person *person = [people objectAtIndex:indexPath.row]; detailViewController.person = person; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; } - (IBAction)addButtonAction:(id)sender { AddPersonController *addViewController = [[AddPersonController alloc] initWithNibName:@"PersonDetail" bundle:nil]; UINavigationController *addNavCon = [[UINavigationController alloc] initWithRootViewController:addViewController]; addViewController.personArray = self.people; [self presentModalViewController:addNavCon animated:YES]; [addViewController release]; [addNavCon release]; } #pragma mark - #pragma mark Memory management - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Relinquish ownership any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. // For example: self.myOutlet = nil; } - (void)dealloc { [addButton release]; [people release]; [super dealloc]; } @end