gpt4 book ai didi

ios - 从子级调用父 View 上的 PerformSegueWithIdentifier 不会更改 View

转载 作者:行者123 更新时间:2023-11-29 00:36:46 25 4
gpt4 key购买 nike

我有一个searchController,它有一个searchResultsController。当我在搜索栏中搜索时,结果 Controller 会显示搜索结果,但是当我点击其中一个单元格时,它不会显示详细 View Controller 。为了让它显示出来,我必须点击搜索栏旁边的取消按钮,当 searchResultsController 消失时,详细信息 View 就会出现。我知道正在从 subview 的父 View 上调用执行segue 函数。 searchResultsController 的 tableview 的委托(delegate)都指向 searchController。

为什么在我点击取消按钮之前 View 不会改变?

下面是一些代码:

搜索 Controller 类:

// 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)类:

// 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];
}

最佳答案

搜索结果 Controller 是一个presented View Controller 。它的 View 覆盖了屏幕并替换了我们开始使用的 View Controller 的 View 。因此,该 View Controller 的 View 不在 View 层次结构中,我们不能离开它。因此,您的代码需要执行您现在手动执行的操作:它需要从取消搜索开始,从而关闭呈现的 View Controller ,以便我们回到第一个 View Controller 并可以从那里继续。

关于ios - 从子级调用父 View 上的 PerformSegueWithIdentifier 不会更改 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40411581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com