开发者

Reload a tableView from the AppDelegate

开发者 https://www.devze.com 2023-02-06 01:24 出处:网络
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

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

精彩评论

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

关注公众号