开发者

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

I've searched this site an开发者_如何学JAVAd 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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜