我有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