当我开始搜索时,我在 UISearchController 中的 UISearchBar 消失了.为什么? [英] My UISearchBar in UISearchController disappear when I start searching. Why?

查看:28
本文介绍了当我开始搜索时,我在 UISearchController 中的 UISearchBar 消失了.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我如何设置我的 UIsearchController

This is how I setup my UIsearchController

private func setupSearchController() {
    let searchResultsController = storyboard!.instantiateViewControllerWithIdentifier(DBSearchOptionControllerIdentifier) as! DBSearchOptionController

    searchController = UISearchController(searchResultsController: searchResultsController)

    let frame = searchController.searchBar.frame
    searchController.searchBar.frame = CGRectMake(0, 50, view.bounds.size.width, 44.0)
    searchController.searchResultsUpdater = self
    view.addSubview(searchController.searchBar)
    searchController.searchBar.text = "mmm"
    view.bringSubviewToFront(searchController.searchBar)
    searchController.searchBar.bringSubviewToFront(view)

}

这是我初始化UISearchController后的样子:

This is how it looks after I initialise UISearchController:

这是我开始在 UISearchBar 中输入时的样子:

This is how it looks when I start typing in UISearchBar:

为什么我的搜索栏消失了?

这很有趣,因为现在当我停止应用程序时,您可以看到它确实在那里:-) 那么为什么它不可见?

This is very interesting, because now when I stop the app, you can see, that it is there, indeed:-) So why it is not visible?

推荐答案

我做了一些测试并找到了一个方法:

I made some testing and found a way:

UISearchBar 肯定必须插入到包装器中:

UISearchBar definitely must be inserted into wrapper:

@IBOutlet weak var wrapperView: UIView!

...

wrapperView.addSubview(searchController.searchBar)

结果如下:

这篇关于当我开始搜索时,我在 UISearchController 中的 UISearchBar 消失了.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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