我已经搜索了这个问题的答案,但我没有找到任何相关的答案。在我的表视图中,当我触摸一个单元格时,会推送一个详细信息视图。源代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"trajetDetail" sender:tableView];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"trajetDetail"]) {
RechercheDetailViewController *detailViewController = segue.destinationViewController;
if (sender == self.searchDisplayController.searchResultsTableView)
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *destinationTitle = [[self.trajets objectAtIndex:[indexPath row]] name];
[detailViewController setTitle:destinationTitle];
}
}}
问题是,当用户使用UISearchBar (和UISearchDisplayController)进行搜索时,他们也可以触摸单元格并被推送到详细视图。
很抱歉我的英语,如果不清楚,请告诉我,我会试着让它更清楚。
最亲切的问候
发布于 2014-10-23 02:09:47
我在你的代码中看到的错误是在你的prepareforsegue方法中,你选择的是标准tableview的索引路径而不是搜索表视图,下面这一行需要改变
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];更改后的prepareForSegue将变成如下所示
您应该改用下面的代码
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"trajetDetail"]) {
RechercheDetailViewController *detailViewController = segue.destinationViewController;
if (sender == self.searchDisplayController.searchResultsTableView)
{
NSIndexPath *indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
NSString *destinationTitle = [[self.trajets objectAtIndex:[indexPath row]] name];
[detailViewController setTitle:destinationTitle];
}
}
}https://stackoverflow.com/questions/26512994
复制相似问题