当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - UISearchBar and Header Title while searching

问题描述:

i've a UISearchBar and when i search for contents, it show only the title of the first section. I have 3 sections, and this code:

- (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");

}

Is that supposed that when i search the title should change depending on the contents of the sections?

I.E. if i have "A" in "First", "B" in "Second", "C", in "Third", should it change to the respective section title for each element i search?

Also, when i search for a content DIFFERENT from the first section (i.e. "C"), and i click on its row, the nib controller doesn't show up. It shows just the elements of the first sections properly.. Why?

网友答案:

First of all we do not know what is the value of your searching variable. its failing because its gives you FALSE value. here is my simple solution. you do not need to check whether is searching mode or not, you can always return default string we assume that is @"Search Results"

- (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;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: