Reload tableView from AppDelegate

I have a pretty simple question, but I still find my way around cocoa. I have a regular rootViewController application created in Xcode. In AppDelegate, I have a function to update the database. When a Push message (didReceiveRemoteNotification :) appears during operation, the data is updated.

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

+7
source share
1 answer

You can use NSNotificationCenter , see NSNotificationCenter class reference

In your rootViewController 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 didReceiveRemoteNotification add the following:

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

All Articles