3

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

Manlio
  • 10,768
  • 9
  • 50
  • 79
Alex
  • 58
  • 1
  • 6

2 Answers2

7

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];
}
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • 1
    It worked great. Thank you :D, I was able to reload both the detailview and the rootview. Fantastic – Alex Sep 06 '11 at 22:18
  • Hi so I'm trying to do the same, but wasn't sure where to place the notificationcenter. Should it go on the rootviewcontroller's class? or the tableview (on the rootview) itself? – gdubs Feb 13 '13 at 22:44
3

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];
}  
Nekto
  • 17,837
  • 1
  • 55
  • 65
  • viewWillAppear or viewdidappear wont be called after you dismiss a modalViewControler – Alex Sep 06 '11 at 22:19