objective-c - 按字母顺序自动分组 UITableView

标签 objective-c uitableview indexing alphabetized

有没有办法按字母顺序自动分组/自动分割我的 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/

相关文章:

objective-c - 同时修改窗框和 View 框

objective-c - 奇怪的崩溃问题为 :- Dispatch queue: com. apple.root.default-overcommit-priority

php - 文本的索引词

mysql - MyISAM 上的 FullText INDEXING 真的很慢

iphone - 无法使用@interface将对象添加到NSMutableArray

iphone - 如何将 UILocatNotification 设置为每天早上 9 点触发

ios - 在 UITableView 上调用scrollToRow 不适用于 AccessoryView

ios - iPad 中 UITableView 中的 CALayer setCornerRadius 滞后?

ios - 检测在 UITableView 中从哪个 Cell 按下 UIButton

python - 尝试在给定的条件下查找名称