在搜索模式下从UITableView删除标题标题 [英] Removing Header Titles from a UITableView in Search Mode

查看:39
本文介绍了在搜索模式下从UITableView删除标题标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处于搜索模式时,我的UITableView刚注意到一些不希望的行为.这是该问题的直观描述,我可疑的方法实现位于底部.

Just noticed some undesired behavior in my UITableView, when it's in search mode. Here is a visual description of the issue, with my suspected method implementation at the bottom.

(第1步)完整列表-确定!

(第2步)搜索结果-确定!

(第3步)深入搜索结果-确定!

(第4步)导航回到搜索结果-不好!所有标头索引都将返回...

这是我的方法实现,它返回所有索引:

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?

谢谢

推荐答案

如果在viewWillAppear:viewDidAppear:中调用[self.tableView reloadData],我会观察到这种情况.

I observed this behavior if [self.tableView reloadData] is called within viewWillAppear: or viewDidAppear:.

似乎reloadData会导致基础表视图的所有节标题都出现,即使搜索处于活动状态,并且仅searchResultsTableView应该是可见的.

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.

一种解决方案可能是仅在[self.searchDisplayController isActive] == NO时才调用reloadData.

A solution could be to call reloadData only if [self.searchDisplayController isActive] == NO.

这篇关于在搜索模式下从UITableView删除标题标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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