I want to make an indexed table.
-(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];
}
But when the app starts, there is only one index named "A". What am i doing wrong?
(Array displays correctly)
Thanks!
You haven't implemented some methods it seems
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_heroes count]/*do according to your need*/;
}
in this case numberOfRowsInSection
should implement very carefully that actually tells you how much row should be under one section (say "A" or "B" etc).
than it may work for you.