简体   繁体   中英

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?

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM