-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”的索引。我究竟做错了什么?

(数组显示正确)

谢谢!

4

1 回答 1

0

你似乎还没有实现一些方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_heroes count]/*do according to your need*/;
} 

在这种情况下numberOfRowsInSection,应该非常小心地实施,它实际上会告诉你一个部分下应该有多少行(比如“A”或“B”等)。

比它可能对你有用。

于 2013-07-29T11:13:15.163 回答