Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 238
Luuk D. Jansen Avatar asked Jan 20 '11 20:01

Luuk D. Jansen


1 Answers

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];
like image 197
WrightsCS Avatar answered Oct 22 '22 09:10

WrightsCS