【发布时间】:2016-12-01 08:55:02
【问题描述】:
我有一个带有UISearchController 的表视图控制器,它将UISearchBar 设置为tableView.tableHeaderView。更新搜索结果时,我使用beginUpdates和endUpdates等相关方法更新table view的数据。
这会使搜索栏消失; tableHeaderView 设置为与搜索栏大小相同的空的通用UIView。如果我只是使用reloadData 而不是整个beginUpdates/endUpdates 过程,一切都很好。
表格视图控制器嵌入在常规视图控制器中;没有涉及导航控制器。这是重现问题所需的表视图控制器的完整实现:
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.tableView.tableHeaderView = self.searchController.searchBar;
}
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
为什么会导致搜索栏被替换为空白视图,如何避免?
【问题讨论】:
-
您是否尝试过更改 viewController/Navigation 控制器上的“半透明”属性?我记得我曾经遇到过这个问题,如果我没记错的话“半透明”它与它有关..
标签: ios uitableview cocoa-touch uisearchbar uisearchcontroller