按字母顺序自动分组UITableView [英] Autogroup UITableView alphabetically

查看:133
本文介绍了按字母顺序自动分组UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法按字母顺序自动分组/自动分区我的 UITableView ?我有一个很大的数组,显示效果很好,但如果我有像Contacts.app这样的部分会更好。

Is there a way to auto group/auto-section my UITableView alphabetically? I have a huge array which is being displayed nicely, but it would be even better if I had the sections like in Contacts.app.

最佳

-f

Best
–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];

这篇关于按字母顺序自动分组UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆