【问题标题】:UISearchBar and Header Title while searching搜索时的 UISearchBar 和标题标题
【发布时间】:2011-08-15 10:48:00
【问题描述】:

我有一个 UISearchBar,当我搜索内容时,它只显示第一部分的标题。我有 3 个部分,这段代码:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(searching)
        return @"Search Results";

    if (section == 0)
        return @"First";
        if(section == 1)
            return  @"Second");
        else
            return @"Third");
}

那是不是假设当我搜索时,标题应该根据章节的内容而改变?

I.E.如果我在“First”中有“A”,在“Second”中有“B”,在“Third”中有“C”,是否应该更改为我搜索的每个元素的相应部分标题?

此外,当我搜索与第一部分不同的内容(即“C”)并单击其行时,笔尖控制器不会显示。它只正确显示了第一部分的元素。为什么?

【问题讨论】:

    标签: objective-c ios4 xcode4 uisearchbar


    【解决方案1】:

    首先,我们不知道您的搜索变量的值是什么。它失败了,因为它给了你 FALSE 价值。这是我的简单解决方案。你不需要检查是否是搜索模式,你总是可以返回我们假设为@“搜索结果”的默认字符串

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
     NSString *headerTitle;
       if (section == 0)
            headerTitle = @"First";
       if(section == 1)
            headerTitle = @"Second");
       else if(section == 2)
            headerTitle = @"Third");
       else
            headerTitle = @"Search Results";
    return headerTitle;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-17
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 2015-12-08
      相关资源
      最近更新 更多