推送View时,UISearchController不会被解雇 [英] UISearchController not dismissed when View is pushed

查看:70
本文介绍了推送View时,UISearchController不会被解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一篇很长的文章,但这只是我保证的一个问题。

I know this is a long write-up, but it's just one issue I promise.

我在使用UISearchController时遇到了一些非常奇怪的行为。让我描述一下层次结构,然后我将逐步解释我的视频中发生的事情:

I'm getting some very strange behavior with a UISearchController. Let me describe the hierarchy, then I'll explain step by step what happens in my video:

你看到的第一个视图是一个常规的ViewController,带有一个tableView和UISearchController作为完全独立的实体。 UISearchController有自己的searchResultsController,我在创建时设置它:

The first view you see is a regular ViewController, with a tableView and the UISearchController as completely separate entities. The UISearchController has its own searchResultsController that I set when I create it:

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

这是基本设置。

指向行为视频的链接

MyResultsControllerClass 有一个tableView,以及一个指向主视图控制器的指针,所有这些视图都放在其中。当searchController的searchBar开始搜索时,你会看到tableView显示出来。然后我点击一个结果,编程俱乐部。 MyResultsControllerClass 使用指向主视图的指针推送新的视图控制器(只是关于该事件的详细信息),如下所示:

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. 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:

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

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

你可以看到这发生在searchBar后面,但是searchController并没有被所呈现的视图掩盖!这是我的问题。如您所见,我仍然可以与之互动。当我按取消时,它最终消失。

You can see this happen behind the searchBar, but the searchController is not "covered up" by the presented view! This is my issue. As you can see, I can still interact with it. When I press "Cancel", it finally disappears.

现在,我认为这可能与UISearchController的事实有关实际上是一个UIViewController,如果我理解正确的话。所以我试图从UISearchController推送,没有任何反应。我尝试将UISearchController嵌入到自己的UINavigationController中并从searchController.navigationController推送,没有任何反应。我可以在推送之前完全取消编辑,但我希望编辑在导航时仍然存在。

Now, I thought this might have to do with the fact that a UISearchController is in fact a UIViewController, if I understand correctly. So I attempted pushing from the UISearchController, nothing happens. I tried embedding the UISearchController in its own UINavigationController and pushing from searchController.navigationController, nothing happens. 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;

。这是Apple在WWDC会议228中推荐的,请在此处阅读: http://asciiwwdc.com/2014/sessions/228

on the view controller that presents the UISearchController. This is recommended by Apple in WWDC session 228, read about it here: http://asciiwwdc.com/2014/sessions/228.

这篇关于推送View时,UISearchController不会被解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆