Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView reloadData - cellForRowAtIndexPath not fired

I have splitViewController which has as MasterViewController some viewController and as DetailViewController some tableViewController. When I push a button on masterViewController I want to show new tableViewController in detailViewController instead of existing one.

So I did like this:

SearchDetailViewController *searchDetailViewController = [[SearchDetailViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *searchDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:searchDetailViewController];

After that I'm passing data to show in new tableController:

[searchDetailViewController passInSearchResults:listOfItems];

After that I "push" new controllers to splitViewController:

[searchSplitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, searchDetailNavigationController, nil]];

In the target tableViewController method "passInSearchResults" data is passed and I also call reloadData. Method looks like that:

- (void)passInSearchResults:(NSMutableDictionary *)searchResults {
    self.searchResultList = searchResults;
    NSLog(@"Data is passed in: %@",self.searchResultList);
    [self.tableView reloadData];
    //[self.tableView setNeedsDisplay];
}

Console: Data is passed in: [here I get the exact data I want and it seems just right].

After this I see that method "numberOfRowsInSection" is fired:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"Setting table length: %i",[self.searchResultList count]);
    return [self.searchResultList count];
}

Console: Setting table length: [here I get proper length]

The problem is that the table is not filled with passed data and method "cellForRowAtIndexPath" is not called.

How can it be that on reloadData method "numberOfRowsInSection" is fired but not method "cellForRowAtIndexPath"... ???

Thanks

like image 575
Borut Tomazin Avatar asked Aug 12 '10 18:08

Borut Tomazin


1 Answers

Check if you are in main thread when calling [self.tableView reloadData];

- (void)passInSearchResults:(NSMutableDictionary *)searchResults {
 if ([NSThread isMainThread]) {
    self.searchResultList = searchResults;
    NSLog(@"Data is passed in: %@",self.searchResultList);
    [self.tableView reloadData];
}
else {
    [self performSelectorOnMainThread:@selector(passInSearchResults:) searchResults waitUntilDone:NO];
}

}

like image 188
andrei Avatar answered Sep 30 '22 17:09

andrei