我有一个 UITableView
,它的数据源和委托(delegate)不是由放置它的 View Controller 处理的,而是由另一个名为 AbstractInviteFriendsDataSourceDelegate
的类处理的。
我在 UITableView
中放置了一个带有 UISearchDisplayController
的 UISearchBar
并手动(不使用 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/