- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
投稿に記載されているように、検索がアクティブな場合はnil を返す必要があります。次に、 の 2 つのメソッドをオーバーライドし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", @"#"];
}
}
self.searchDisplayController.active
注: if 条件で使用する必要があることがわかりました。を使用すると機能しませんtableView != self.tableView
。