Reload a tableView from the AppDelegate

回眸只為那壹抹淺笑 提交于 2019-12-10 03:43:41

问题


I have a pretty simple question, but am still finding my way around cocoa. I have a normal rootViewController App as created in Xcode. In the AppDelegate I have a function to update the database. When a Push-message comes in while running (didReceiveRemoteNotification:) the data is updated.

But how do I get a handle on the the RootViewController telling it to update its objects and then reload the table (which is a function)?


回答1:


You can use NSNotificationCenter, see NSNotificationCenter Class Reference

In your rootViewController's viewDidLoad, add the following:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateView:) name:@"updateRoot" object:nil];

and add the following method:

- (void)updateView:(NSNotification *)notification {
    [myTableView reloadData]; 
}

In your AppDelegate's didReceiveRemoteNotification, add the following:

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateRoot" object:nil];


来源:https://stackoverflow.com/questions/4752055/reload-a-tableview-from-the-appdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!