在UINavigationController中的TableViewController中消失的UISearchController [英] Disappearing UISearchController in a TableViewController that is in a UINavigationController

查看:435
本文介绍了在UINavigationController中的TableViewController中消失的UISearchController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用UISearchBar作为表的标题制作了一个UITableView控制器.

I have made a UITableView Controller with a UISearchBar as the Table's header.

然后我已将此视图控制器作为根视图控制器嵌入到UINavigationController中.

I have then embedded this View Controller into a UINavigationController, as the root view controller.

现在,当我点击搜索栏时,搜索栏似乎消失并显示白色屏幕.出现键盘,但是没有搜索栏. 表格视图可以滚动,但是搜索栏完全消失了.

Now, when I tap on the Search Bar, the SearchBar seems to disappears and displays a white screen. The keyboard appears, but there is no Search Bar. The Table View can scroll, but the search bar has simply vanished.

当我在没有导航控制器的情况下实现此UITableViewController 时,它可以完美运行.但是有关Navigation Controller的某些知识使一切变得无聊.

When I implement this UITableViewController without the Navigation Controller, it works perfectly. But something about the Navigation Controller is borking everything up.

推荐答案

我遇到了有时会发生的相同问题,尤其是在行数少(少于50行)的表视图中. 看来searchBar已从视图层次结构中删除,确切地说是从UISearchControllerView的子级容器视图中删除了.

I've had the same issue that was sometimes happening, especially with table view of small number of rows (less than 50). It appears the searchBar is removed from the view hierarchy, precisely from the container view that is a child of the UISearchControllerView.

我找到了一种解决方法,可以手动将搜索栏重新添加为UISearchControllerView容器子项的子视图.这是在委托函数(来自UISearchControllerDelegate)didPresentSearchController中实现的:

I've found a workaround to manually add back the searchbar as a subview of the UISearchControllerView container child. This is implemented in the delegate function (from UISearchControllerDelegate) didPresentSearchController:

func didPresentSearchController(searchController: UISearchController) {
    if searchController.searchBar.superview == nil {
        for searchCtrlChildView in searchController.view.subviews {
            if searchCtrlChildView.frame.origin == CGPoint(x: 0, y: 0) { //Discriminate if by chance there was more than one subview
                searchCtrlChildView.addSubview(searchController.searchBar)
                break
            }
        }
    }
}

由于iOS 8.4中未解决此问题,因此我也向Apple提出了雷达

I've also filed a radar to Apple on this as it is not fixed in iOS 8.4

这篇关于在UINavigationController中的TableViewController中消失的UISearchController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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