2012-11-20 40 views
-1

我有一个splitView应用程序,我已经安装了搜索/过滤。IOS - 搜索/过滤后,如何选择rowAtIndexPath

过滤工作的主视图,但我不知道如何设置“didSelectRowAtIndexPath”。似乎根和细节之间的链接丢失了。

我尝试使用此代码重新连接:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    indexPath = [self.tableView indexPathForSelectedRow]; 

    if (tableView == self.searchDisplayController.searchResultsTableView) 
    { 
     self.selectedItem = [self.searchResults objectAtIndex:indexPath]; 
    } 
    else 
    { 
     self.selectedItem = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    } 

    detailViewController.item = self.selectedItem; 
    [self.detailViewController.tableView reloadData]; 

但是,这并不让我有NSRangeException。

相反,如果我使用:

self.selectedItem = [self.searchResults objectAtIndex:indexPath.row]; 

也不例外,但细节视图不捕获。

我很感激任何帮助。

+0

为什么你要调用'indexPath = [self.tableView indexPathForSelectedRow];'而不是使用'indexPath'作为参数提供给函数? –

+0

辉煌。就是这样..非常感谢。如果你可以建议这个答案,我会马上接受。有时候,第二双眼睛是所有需要的。再次感谢你.. –

回答

2

这是没有必要的(也可能是错误的)打电话给

indexPath = [self.tableView indexPathForSelectedRow]; 

因为所选行作为参数提供给tableView:didSelectRowAtIndexPath: