你必須在你的搜索是積極的,因爲您在您的文章注意- (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