-1
我想創建一個索引表。索引表中只有一個部分
-(void)awakeFromNib
{
self.heroes = [NSArray arrayWithObjects: @"Aaaa",@"Abbbbb",@"Bbbbb",@"Nnnnn",@"Pppp",@"Xxxx",@"Zzzzz", nil];
}
- (NSArray *)sortedArrayFromArray:(NSArray *)array collationStringSelector:(SEL)selector{
return [NSArray arrayWithObjects:@"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", nil];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex: section];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index];
}
但是,當應用程序啓動時,只有一個名爲「A」的索引。我究竟做錯了什麼?
(陣列顯示正確)
謝謝!
你有這個方法嗎? - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView – Sauvage
這裏有詳細的例子http://www.iphonedevcentral.com/indexed-uitableview-tutorial/ – Sauvage