Nathan187 Nathan187 - 1 month ago 10
iOS Question

iPad SplitViewController: Reloading the root view controller's tableview from the detail view controller

I've searched this site and the web and just looking for a simple example on how to reload the root view controller's table view from the detail view. I've tried notifications, setting a tableview in the detailview controller equal to the tableview of the rootview controller...nothing works.

Has anyone experienced this or have any sample code?

Answer

Use notificationcenter to pass a notification from the detail to the rootviewcontroller telling it to reload the data.

ex: IN ROOT VIEW CONTROLLER

(where i've created a method called reloadRootTable, that calls [self.tableView reloadData];)

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadRootTable) name:@"reloadRootTable" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"reloadRootTable" object:nil];
    [super viewWillDisappear:animated];
}

IN DETAILVIEWCONTROLLER:

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadRootTable" object:nil];
Comments