ios - UISearchBar 在点击时消失

标签 ios uitableview delegates uisearchbar

我有一个 UITableView,它的数据源和委托(delegate)不是由放置它的 View Controller 处理的,而是由另一个名为 AbstractInviteFriendsDataSourceDelegate 的类处理的。

我在 UITableView 中放置了一个带有 UISearchDisplayControllerUISearchBar 并手动(不使用 Storyboard界面)将它们的委托(delegate)和数据源设置为处理 UITableView 的数据源和委托(delegate)的 Controller 。

- (id)init
{
    self = [super init];
    if (self) {
        friendsArray = [FriendsToInvite new];
        UISearchBar *searchBar = [self.delegate theSearchBar];
        searchBar.delegate = self;
        UISearchDisplayController *searchDisplay = [self.delegate theSearchDisplayController];
        searchDisplay.delegate = self;
        searchDisplay.searchResultsDataSource = self;
        searchDisplay.searchResultsDelegate = self;
    }
    return self;
}

我认为这没问题,因为当我实现搜索栏的委托(delegate)方法之一时,它被正确调用了。

但是现在,当我点击搜索栏时,它会向左滑动以为取消按钮腾出空间,然后它就消失了。我没有为 UISearchBar 委托(delegate)实现任何方法,也没有为 UISearchDisplayController 委托(delegate)和数据源实现任何方法。

我尝试实现 searchBarShouldBeginEditing 只是为了查看它是否在搜索栏消失之前被调用,是的,它被调用了,但是在此方法返回后搜索栏消失了。

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    return YES;
}

编辑: 我已经解决了这个问题,似乎我有 Storyboard中的 searchContentController 导出。我将其设置回包含 TableView 的 View Controller ,现在可以了。

最佳答案

我也遇到了同样的问题,通过在表格 View 中添加搜索栏来解决。

关于ios - UISearchBar 在点击时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20116469/

相关文章:

ios - 如何加入圆角线

ios - 此类与键的键值编码不兼容...为什么?

objective-c - 如何使用单个NSArray在UITbleViewCell中创建节?

ios - 在具有 UITableView 的 UICollectionView 中拖放

c# - 带有事件处理程序的 VB.NET 到 C#

ios - UILongPressGestureRecognizer 中的 While 循环不起作用

ios - NSTimer 选择器即使在后台也会不断被调用

iphone - 在 iPad 和 iPhone 上显示 UIwebview

c++ - C++11 中的委托(delegate)

c++ - 什么是 C++ 委托(delegate)?