简体   繁体   English

从子级调用父级视图上的performSegueWithIdentifier不会更改视图

[英]Calling performSegueWithIdentifier on parent view from child doesn't change view

I have a searchController and it has a searchResultsController. 我有一个searchController,它有一个searchResultsController。 When I search in the search bar the results controller shows the search results, but when I tap on one of the cells it doesn't show the detail view controller. 当我在搜索栏中搜索时,结果控制器会显示搜索结果,但是当我点击其中一个单元格时,它不会显示详细视图控制器。 To get it to show, I have to hit the cancel button beside the search bar and when the searchResultsController disappears, the detail view appears. 为了使其显示,我必须单击搜索栏旁边的“取消”按钮,并且当searchResultsController消失时,将显示详细信息视图。 I know the perform segue function is being called on the parent view from the child view. 我知道在子视图的父视图上正在调用perform segue函数。 The delegates for the tableview of the searchResultsController are all pointing to the searchController. searchResultsController的tableview的委托都指向searchController。

Why is the view not changing until I hit the cancel button? 为什么在我单击“取消”按钮后视图才改变?

Here's some of the code: 这是一些代码:

Search controller class: 搜索控制器类:

// parent view controller
- (void) showContact:(Contact*)contact
{
    NSLog(@"Did tap contact id:[%@]",contact.id);
    [self performSegueWithIdentifier:@"contactPressed" sender:contact];
}

- (void)contactsSearchTableDelegate:(ContactsSearchTableDelegate *)delegate
                  didTapContact:(Contact *)contact
{
    [self showContact:contact];
}

Delegate Class: 代表班:

// delegate, searchController and searchResultsController both point here
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate contactsSearchTableDelegate:self didTapContact:[self contactAtIndexPath:indexPath]];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

A search results controller is a presented view controller. 搜索结果控制器是显示的视图控制器。 Its view covers the screen and replaces the view of the view controller we started with. 它的视图覆盖了屏幕,并替换了我们最初使用的视图控制器的视图。 Thus, that view controller's view is not in the view hierarchy and we can't go anywhere from it. 因此,该视图控制器的视图不在视图层次结构中,因此我们无法走到任何地方。 Thus, your code needs to do what you are doing manually now: it needs to start by cancelling the search and thus dismissing the presented view controller, so that we are back to the first view controller and can proceed from there. 因此,您的代码需要立即执行您现在正在做的事情:首先需要取消搜索,然后关闭显示的视图控制器,以便我们回到第一个视图控制器,并可以从那里开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM