我在使用带有节标题的索引表时遇到问题.目前我在右侧有索引,我有正确显示的部分标题,标题只显示该部分内是否有数据.
我遇到的问题是将NSArray分成几部分,这样我就可以正确计算numberOfRowsInSections.目前我有正确数量的部分显示正确的标题,但所有数据都在每个部分,而不是根据名称的第一个字母拆分.
以下是目前的截图:
所有数据都分为每个部分,每行5行.部分(3)的数量是正确的
我的代码如下:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [firstLetterArray objectAtIndex:section];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSMutableSet *mySet = [[NSMutableSet alloc] init];
BRConnection *connection = nil;
NSMutableArray *firstNames = [[NSMutableArray alloc] init];
for (connection in _connections)
{
[firstNames addObject:connection.firstName];
}
firstNamesArray = firstNames;
NSLog(@"%@", firstNamesArray);
for ( NSString *s in firstNames)
{
if ([s length] > 0)
[mySet addObject:[s substringToIndex:1]];
}
NSArray *indexArray = [[mySet allObjects] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
firstLetterArray = indexArray;
return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}
- …Run Code Online (Sandbox Code Playgroud)