开发者

Reload a tableView from the AppDelegate

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)?


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜