I'm using a UISplitviewController
as a template.
action开发者_如何学运维 for edit button:
newExViewController *editWindow =[[newExViewController alloc]initWithNibName:@"newExViewController" bundle:nil];
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:editWindow];
navBar.modalPresentationStyle = UIModalPresentationFormSheet;
navBar.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navBar animated:YES];
[navBar release];
[editWindow release];
navBar
has a UIBarButton
for saveButton. This is called when you press SaveButton
[self dismissModalViewControllerAnimated:YES];
now is the problem: any idea how to reload the data for both the main NavigationConteroller and the detailViewController when the modalView is dismissed?? I have no clue thnx
You should look into NSNotificationCenter
. In your view with the UITableView, create the notification listener. Then in the view that dismisses, call that notification.
To be more specific, the Notification will call a method that should contain reloadData
.
Example
The following should go with the UITableView you want to reload:
This could go along with your [self dismissModalViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethodToReloadTable) name:@"reloadTable" object:nil];
This is how you will call the notification center to reload the table:
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTable" object:self];
Example of the notification method:
- (void)someMethodToReloadTable:(NSNotification *)notification
{
[myTableView reloadData];
}
And don't forget to remove the notificaiton observer:
-(void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"reloadTable" object:nil];
}
In controllers, that contains view you want to reload, you should decline following method which will be called when the modalView
will be dismissed (or when controller's main view will be first time loaded):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// here you can reload needful views, for example, tableView:
[tableView reloadData];
}
精彩评论