SearchBar从iOS 7中的headerview中消失 [英] SearchBar disappears from headerview in iOS 7

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

问题描述

我有一个 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,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中的headerview中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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