Here's a basic overview of how I've done this. It's worked for me but I'm not sure it's the best way--others will surely chime in.
The "list page" (your first UITableViewController) implements a delegate that the "add page" calls into to let the "list page" know the details of the item to add.
When the "list page" gets called back by the "add page" with said details, it saves the new item and then closes the "add page".
To get this all hooked up, when the "list page" creates and displays the "add page", it passes self
to an ivar on the "add page" (that I call delegate
). That's basically how the two get linked and communicate.
Here's a protocol I define for the delegate:
@protocol AddItemViewControllerDelegate
- (void)addItemViewController:(AddItemViewController *)controller
withNewEventName:(NSString *)eventName;
@end
Here's the "list page" button click handler:
- (IBAction)addItem
{
AddItemViewController *controller = [[AddItemViewController alloc] initWithNibName:@"AddItemView" bundle:nil];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Here's the commit code from the "add page":
if ([self.delegate respondsToSelector:@selector(addItemViewController:withNewEventName:)]) {
[self.delegate addItemViewController:self withNewEventName:eventNameTextField.text];
}
Finally, here's the implementation of the delegate protocol in the "list page":
- (void)addItemViewController:(AddItemViewController *)controller
withNewEventName:(NSString *)eventName
{
EventModel *newEvent = [[EventModel alloc] init];
newEvent.name = eventName;
[eventsList addObject:newEvent];
[newEvent release];
[self saveEvents];
[self dismissModalViewControllerAnimated:YES];
}