SearchBar 从 iOS 7 的标题视图中消失 [英] SearchBar disappears from headerview in iOS 7

查看:23
本文介绍了SearchBar 从 iOS 7 的标题视图中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tableview 用于在我的应用程序中显示设备列表.当调用 viewWillAppear 时,我将 self.searchDisplayController.searchBar 作为子视图添加到 headerView.然后我分配 self.tableView.tableHeaderView = headerView.它看起来像这样:

I have a tableview for showing a list of devices in my application. When viewWillAppear is called, I add the self.searchDisplayController.searchBar as a subview to a headerView. I then assign self.tableView.tableHeaderView = headerView. It looks like this:

我向下滚动 tableview,以便 headerview 消失,然后通过点击单元格转到其他一些视图控制器.当我回到这个 tableView 时,向上滚动到 headerView,searchBar 变得不可见,但是在点击不可见区域时,searchDisplayController 被激活并且取消按钮不起作用.这只发生在 iOS 7 上.为什么会这样?
注意:只有当我回到 tableViewController 时 headerView 不在视图中时才会发生这种情况.

I scroll the tableview down so that headerview goes out of view and then go to some other view controller by tapping on a cell. When I come back to this tableView, scroll up to the headerView, the searchBar becomes invisible, however on tapping the invisible area the searchDisplayController gets activated and the cancel button doesn't work. This happens for iOS 7 only. Why is this happening?
Note: It happens only if the headerView is out of the view when I come back to the tableViewController.

推荐答案

我刚刚遇到了同样的问题.当我在搜索结束状态下调试到 UISearchDisplayController 的委托方法时,searchBar 变成了 UIView 的子视图,而不是 UITableView.请看下面的代码:

I've just had the same issue. When I go to debug into the delegate method of UISearchDisplayController at the end search state, the searchBar becomes a subview of an UIView, not the UITableView. Please see below code:

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
    //My Solution: remove the searchBar away from current super view,
    //then add it as subview again to the tableView
    UISearchBar *searchBar = controller.searchBar;
    UIView *superView = searchBar.superview;
    if (![superView isKindOfClass:[UITableView class]]) {
        NSLog(@"Error here");
        [searchBar removeFromSuperview];
        [self.tableView addSubview:searchBar];
    }
    NSLog(@"%@", NSStringFromClass([superView class]));
}

我的解决方案是将 searchBar 从当前超级视图中移除,然后将其作为子视图再次添加到 tableView.我已经测试成功了.希望有所帮助!

My solution is remove the searchBar away from current super view, then add it as subview again to the tableView. I've already tested successfully. Hope that help!

问候

这篇关于SearchBar 从 iOS 7 的标题视图中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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