我有一個賽格瑞在那裏我試圖讓當前所選行一個UITableViewController:indexPathForSelectedRow返回nil
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"EditFilterElementSegue"]){
// Get the element that was clicked and pass it to the view controller for display
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
Element *element = [fetchedResultsController objectAtIndexPath:selectedIndexPath];
FilterElementTableViewController *vc = segue.destinationViewController;
vc.filter = filter;
vc.element = element;
}
}
問題是indexPathForSelectedRow將返回零。文檔說,如果索引路徑無效,返回nil。如果我添加:
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:0];
selectedIndexPath = [self.tableView indexPathForSelectedRow];
selectedIndexPath有效。所以,我目前假設該行以某種方式被取消選中。任何人都可以告訴我如何確定是否是這種情況以及可能導致它的原因?
此代碼工作正常,直到我轉換爲使用NSFetchedResultsController(否則正在工作)。我也在其他幾個表視圖控制器中使用indexPathForSelectedRow工作正常(其中之一也使用NSFetchedResultsController)。
我也試過打破didSelectRowAtIndexPath,但同樣的事情發生在那裏。 (預料的,因爲它prepareForSegue後調用。)
對我來說,我是取消了我的排。 「衛生署! – Baub 2012-04-26 23:36:17