首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >didSelectRowAtIndexPath UISearchBar

didSelectRowAtIndexPath UISearchBar
EN

Stack Overflow用户
提问于 2014-10-23 01:01:21
回答 1查看 173关注 0票数 0

我已经搜索了这个问题的答案,但我没有找到任何相关的答案。在我的表视图中,当我触摸一个单元格时,会推送一个详细信息视图。源代码:

代码语言:javascript
复制
- (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)进行搜索时,他们也可以触摸单元格并被推送到详细视图。

很抱歉我的英语,如果不清楚,请告诉我,我会试着让它更清楚。

最亲切的问候

EN

回答 1

Stack Overflow用户

发布于 2014-10-23 02:09:47

我在你的代码中看到的错误是在你的prepareforsegue方法中,你选择的是标准tableview的索引路径而不是搜索表视图,下面这一行需要改变

代码语言:javascript
复制
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

更改后的prepareForSegue将变成如下所示

您应该改用下面的代码

代码语言:javascript
复制
- (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];
    }


}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26512994

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档