data loading - app launching on tableview
i encounter an issue with my application.
On one hand when my app launches, the first view displayed is a table开发者_运维百科view within a tableviewcontroller.
On the other hand my app calls a web service to collect data. These methods are in MyAppDelegate\applicationDidFinishLaunching.
The thing is that my tableview is made of custom cells that need data from the web service.
I noticed that the view (with the tableview) is launched first and then MyAppDelegate\applicationDidFinishLaunchin is executed.
As a result the labels of my custom cells are all equal to null as my arrays aren't filled yet by the web service.
I would like to know the proper way to make it.
If anyone has an idea please tell me.
Wallou
Use NSNotificationCenter to communicate to your UITableViewController that it needs to reloadData for the table.
To Register (in your UITableViewController.viewDidLoad):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dataLoaded:)
name:@"myapp.dataloaded" object:nil];
- (void)dataLoaded:(NSNotification *)notification
{
[self.table reloadData];
}
To post notifications (after you loaded the data):
[[NSNotificationCenter defaultCenter]
postNotificationName:@"myapp.dataloaded" object:nil];
精彩评论