有没有办法按字母顺序自动分组/自动分割我的 UITableView
?我有一个巨大的数组,可以很好地显示,但如果我有像 Contacts.app 中那样的部分,那就更好了。
最佳
–f
最佳答案
首先定义部分
self.sections = [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];
然后
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 27;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.sections;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index
{
return index;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [self.sections objectAtIndex:section];
}
之后按字母过滤
NSArray *sectionArray = [vendorList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [self.sections objectAtIndex:section]]];
rowCount = [sectionArray count];
关于objective-c - 按字母顺序自动分组 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3377254/