I’d like to run the code [tableView reloadData], except I want to call it from a seperate class to the view controller I want to reload the data in.
(Note. If there is something more effective to reload a tableview than reloadData, chime in).
Say the view I want to reload is ‘RootViewController’, and I am currently in ‘DetailViewController’, what do i need to do to make it work.
My best attempt right now is [RootViewController.tableView reloadData], but its not right.
(I get error: expected ‘:’ before . token.
Regards, @norskben
You can use notifications or a protocol.
Using notifications:
post a notification just after finishing saving the data and before returning from the method. Something like this:
// post notification
[[NSNotificationCenter defaultCenter] postNotificationName:@”DataSaved” object:nil];
In the controller handling the table, implement
and in its
viewDidLoadmethod add the following code to register for notifications:finally, unregister in the dealloc method adding
Using a protocol:
start creating a protocol with a callback that your previous controller can use.
once you finish saving your data:
now, in your previous controller you handle the delegate method: in the
dataSaved()method you reload your table.