简体   繁体   English

推送View时,UISearchController不会被解雇

[英]UISearchController not dismissed when View is pushed

I know this is a long write-up, but it's just one issue I promise. 我知道这是一篇很长的文章,但这只是我保证的一个问题。

The Setup 安装程序

I'm getting some very strange behavior with a UISearchController. 我用UISearchController得到了一些非常奇怪的行为。 Let me describe the hierarchy, then I'll explain step by step what happens in my video: 让我描述一下层次结构,然后我将逐步解释我视频中发生的事情:

The first view you see is a regular ViewController, with a tableView and the UISearchController as completely separate entities. 您看到的第一个视图是常规ViewController,其中tableView和UISearchController是完全独立的实体。 The UISearchController has its own searchResultsController that I set when I create it: UISearchController有自己的searchResultsController,我在创建时设置它:

let searchResultsController = MyResultsControllerClass()
searchController = UISearchController(searchResultsController: searchResultsController)

That's the basic setup. 这是基本的设置。

The Behavior 行为

A link to a video of the behavior 指向行为视频的链接

The MyResultsControllerClass has a tableView, as well as a pointer back to the master view controller all these views are housed in. When the searchController's searchBar begins searching, you see that tableView show up. MyResultsControllerClass有一个tableView,以及一个指向主视图控制器的指针,所有这些视图都放在其中。当searchController的searchBar开始搜索时,你会看到tableView显示出来。 Then I tap a result, Programming Club. 然后我点击一个结果,编程俱乐部。 The MyResultsControllerClass uses the pointer to the master view to push a new view controller (just details about that event) like so: MyResultsControllerClass使用指向主视图的指针来推送新的视图控制器(只是关于该事件的详细信息),如下所示:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let activityDetail = ActivityDetailViewController(nibName: nil, bundle: nil, activity: searchResults[indexPath.row])
    parentController?.navigationController?.pushViewController(activityDetail, animated: true)
}

You can see this happen behind the searchBar, but the searchController is not "covered up" by the presented view! 您可以在searchBar后面看到这种情况,但是searchController不会被呈现的视图“掩盖”! This is my issue. 这是我的问题。 As you can see, I can still interact with it. 如您所见,我仍然可以与之互动。 When I press "Cancel", it finally disappears. 当我按“取消”时,它最终消失。

What I've tried 我试过的

Now, I thought this might have to do with the fact that a UISearchController is in fact a UIViewController, if I understand correctly. 现在,我认为这可能与UISearchController实际上是UIViewController的事实有关,如果我理解正确的话。 So I attempted pushing from the UISearchController, nothing happens. 所以我试图从UISearchController推送,没有任何反应。 I tried embedding the UISearchController in its own UINavigationController and pushing from searchController.navigationController, nothing happens. 我尝试将UISearchController嵌入到自己的UINavigationController中并从searchController.navigationController推送,没有任何反应。 I can completely cancel the editing before pushing, but I want the editing to still exist when they navigate back. 我可以在推送之前完全取消编辑,但我希望编辑在导航时仍然存在。

What am I doing wrong? 我究竟做错了什么? Is there a better way to do this? 有一个更好的方法吗?

I have the same exact issue, I have solved it by setting: 我有同样的问题,我通过设置解决了它:

self.definesPresentationContext = YES;

on the view controller that presents the UISearchController. 在提供UISearchController的视图控制器上。 This is recommended by Apple in WWDC session 228, read about it here: http://asciiwwdc.com/2014/sessions/228 . 这是Apple在WWDC会议228中推荐的,请在此处阅读: http//asciiwwdc.com/2014/sessions/228

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

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