Created
November 3, 2010 19:04
-
-
Save ironfounderson/661529 to your computer and use it in GitHub Desktop.
Presenting a modal view controller using delegate pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)insertNewObject { | |
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; | |
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity]; | |
Book *newBook = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; | |
BookViewController *bookViewController = [[BookViewController alloc] init]; | |
bookViewController.book = newBook; | |
bookViewController.delegate = self; | |
[self presentModalViewController:bookViewController animated:YES]; | |
[bookViewController release]; | |
} | |
- (void)bookViewControllerDidSave:(BookViewController *)controller { | |
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; | |
NSError *error = nil; | |
if (![context save:&error]) { | |
NSLog(@"Unresolved error %@, %@", error, [error userInfo]); | |
abort(); | |
} | |
[self.tableView reloadData]; | |
[self dismissModalViewControllerAnimated:YES]; | |
} | |
- (void)bookViewControllerDidCancel:(BookViewController *)controller { | |
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; | |
[context rollback]; | |
[self dismissModalViewControllerAnimated:YES]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment