[英]Removing Header Titles from a UITableView in Search Mode
Just noticed some undesired behavior in my UITableView, when it's in search mode. 刚刚注意到我的UITableView中有一些不受欢迎的行为,当它处于搜索模式时。 Here is a visual description of the issue, with my suspected method implementation at the bottom.
这是对问题的直观描述,我怀疑的方法实现在底部。
(Step 1) The Complete List - OK! (第1步)完整清单 - 好的!
(Step 2) Search Results - OK! (第2步)搜索结果 - 好的!
(Step 3) Drill Into a Search Result - OK! (步骤3)深入搜索结果 - 好的!
(Step 4) Navigate Back to Search Results - Not OK! (步骤4)导航回搜索结果 - 不行! All Header indexes are being returned...
正在返回所有标头索引...
Here is my method implementation that is returning all of the indices: 这是我的方法实现,它返回所有索引:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSArray *sKeysArray = [[listContent allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
sorted = [sKeysArray sortedArrayUsingComparator:self.mySortBlock];
if (tableView == self.searchDisplayController.searchResultsTableView){
return @"";
} else {
return [sorted objectAtIndex:section];
}
}
What are best practices to solve this issue? 解决此问题的最佳做法是什么?
Thanks 谢谢
I observed this behavior if [self.tableView reloadData]
is called within viewWillAppear:
or viewDidAppear:
. 如果在
viewWillAppear:
或viewDidAppear:
调用[self.tableView reloadData]
我会观察到这种行为。
It seems that reloadData
causes all section headers of the underlying table view to appear even if a search is active and only the searchResultsTableView
should be visible. 似乎
reloadData
导致基础表视图的所有节头都出现,即使搜索处于活动状态且只有searchResultsTableView
可见。
A solution could be to call reloadData
only if [self.searchDisplayController isActive] == NO
. 解决方案可能是仅在
[self.searchDisplayController isActive] == NO
调用reloadData
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.