xcode 推送视图时未关闭 UISearchController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29610873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UISearchController not dismissed when View is pushed
提问by Kyle Bashour
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. Let me describe the hierarchy, then I'll explain step by step what happens in my video:
UISearchController 出现了一些非常奇怪的行为。让我描述一下层次结构,然后我将逐步解释我的视频中发生的事情:
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:
你看到的第一个视图是一个普通的 ViewController,一个 tableView 和 UISearchController 作为完全独立的实体。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. 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
有一个 tableView,以及一个指向所有这些视图都包含在其中的主视图控制器的指针。当 searchController 的 searchBar 开始搜索时,您会看到 tableView 出现。然后我点击一个结果,Programming Club。在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! This is my issue. As you can see, I can still interact with it. When I press "Cancel", it finally disappears.
您可以在 searchBar 后面看到这种情况,但是 searchController 并没有被呈现的视图“掩盖”!这是我的问题。如您所见,我仍然可以与它互动。当我按“取消”时,它终于消失了。
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. 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.
现在,我认为这可能与 UISearchController 实际上是 UIViewController 的事实有关,如果我理解正确的话。所以我尝试从 UISearchController 推送,没有任何反应。我尝试将 UISearchController 嵌入到它自己的 UINavigationController 中并从 searchController.navigationController 推送,但没有任何反应。我可以在推送之前完全取消编辑,但我希望编辑在他们导航回来时仍然存在。
What am I doing wrong? Is there a better way to do this?
我究竟做错了什么?有一个更好的方法吗?
回答by Chris Jenkins
I have the same exact issue, I have solved it by setting:
我有同样的问题,我通过设置解决了它:
self.definesPresentationContext = YES;
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.
在呈现 UISearchController 的视图控制器上。这是 Apple 在 WWDC session 228 中推荐的,请在此处阅读:http: //asciiwwdc.com/2014/sessions/228。