【问题标题】:Only one section in Indexed Table索引表中只有一个部分
【发布时间】:2013-07-29 10:30:46
【问题描述】:

我想制作一个索引表。

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

(数组显示正确)

谢谢!

【问题讨论】:

标签: ios tableview indexed


【解决方案1】:

你似乎没有实现一些方法

- (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”等)。

它可能对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-11
    • 2019-07-03
    • 2021-06-03
    • 2018-09-29
    • 2018-09-24
    • 2015-03-24
    相关资源
    最近更新 更多