2013-07-29 2 views
-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». Что я делаю не так?

(Отображаются массивы правильно)

Спасибо!

+0

У вас есть этот метод? - (NSInteger) numberOfSectionsInTableView: (UITableView *) tableView – Sauvage

+0

здесь есть подробный пример http://www.iphonedevcentral.com/indexed-uitableview-tutorial/ – Sauvage

ответ

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» и т.д.).

чем он может работать на вас.

Смежные вопросы