我有splitViewController它有MasterViewController一些viewController和DetailViewController一些tableViewController。当我在masterViewController上按下按钮时,我想在detailViewController中显示新的tableViewController而不是现有的。UITableView reloadData - cellForRowAtIndexPath未被触发
所以,我没有这样的:
SearchDetailViewController *searchDetailViewController = [[SearchDetailViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *searchDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:searchDetailViewController];
之后,我传递的数据在新tableController显示:
[searchDetailViewController passInSearchResults:listOfItems];
我 “推” 的新控制器splitViewController后:
[searchSplitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, searchDetailNavigationController, nil]];
在目标tableViewController方法“passInSearchResults”中传递数据,我也调用reloadDa TA。方法看起来像这样:
- (void)passInSearchResults:(NSMutableDictionary *)searchResults {
self.searchResultList = searchResults;
NSLog(@"Data is passed in: %@",self.searchResultList);
[self.tableView reloadData];
//[self.tableView setNeedsDisplay];
}
控制台:数据在传递:在这里我得到了我想要的确切数据,似乎恰到好处。
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];
}
控制台:设置表的长度:在这里我得到适当的长度]
的问题是,该表中不填充传递的数据和方法“的cellForRowAtIndexPath”不叫。
怎么可能是reloadData方法“numberOfRowsInSection”被激发,但不是方法“cellForRowAtIndexPath”... ???
感谢
没有必要先检查您是否在主线程上运行。 'performSelectorOnMainThread'可以工作,即使你已经在主线程上了,就像'dispatch_async(dispatch_get_main_queue()')一样(这可能是你在这里实际需要的)在这里添加'if'只会消耗不必要的处理器周期。 – 2016-11-28 23:05:53