你必须在你的搜索是积极的,因为您在您的文章注意- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
返回nil。然后,重写UISearchDisplayDelegate
中的两个方法来刷新索引。
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
[self.tableView reloadSectionIndexTitles];
}
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
[self.tableView reloadSectionIndexTitles];
}
对于sectionIndexTitlesForTableView
方法,我更喜欢使用:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
if (self.searchDisplayController.active) {
return nil;
} else {
//Add @"{search}", to beginning to add search icon to top of index
return @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"#"];
}
}
注:我发现,你必须在if条件使用self.searchDisplayController.active
。如果您使用,则不起作用。
有什么意见吗? – Tony 2012-07-17 19:29:14
仍然希望有人能帮助我。谢谢。 – Tony 2012-07-25 16:57:37