0

如何检查 segue 中的当前 tableview 是什么?由于 UISearchDisplayController 激活了它自己的 tableview,我得到了另一个带有结果的数组。

这是我尝试过的代码,但它不起作用。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetails"]) {        
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];    
        if (self.tableView == [[self searchDisplayController]searchResultsTableView]) {
        }
        DetailViewController *detailViewController = [segue destinationViewController];
        detailViewController.myObject = [mySearchArray objectAtIndex:indexPath.row];
    }
}
4

1 回答 1

0

根据Apple网站,方法内部:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {...}

你会检查 tableView

if (tableView == self.tableView) {
    return ...;
}
// If necessary (if self is the data source for other table views),
// check whether tableView is searchController.searchResultsTableView.
return ...;
于 2012-04-20T07:10:51.460 回答