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
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];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With