TableVIew实现类似于电话本的首字母索引
2013-06-05 10:11
357 查看
实际上UITableView默认就支持象电话本那样的按首字母索引。 实现sectionIndexTitlesForTableView 和 sectionForSectionIndexTitle 这两个接口即可。 细节请参考UITableViewDataSource帮助文档。
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSMutableArray *toBeReturned = [[NSMutableArray alloc]init];
for(char c = ‘A’;c<=‘Z’;c++)
[toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];
return toBeReturned;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
NSInteger count = 0;
for(NSString *character in arrayOfCharacters)
{
if([character isEqualToString:title])
{
return count;
}
count ++;
}
return 0;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if([arrayOfCharacters count]==0)
{
return @”";
}
return [arrayOfCharacters objectAtIndex:section];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSMutableArray *toBeReturned = [[NSMutableArray alloc]init];
for(char c = ‘A’;c<=‘Z’;c++)
[toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];
return toBeReturned;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
NSInteger count = 0;
for(NSString *character in arrayOfCharacters)
{
if([character isEqualToString:title])
{
return count;
}
count ++;
}
return 0;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if([arrayOfCharacters count]==0)
{
return @”";
}
return [arrayOfCharacters objectAtIndex:section];
}
相关文章推荐
- UITableVIew实现类似于电话本的首字母索引
- UITableVIew实现类似于电话本的首字母索引
- 利用tableView分组实现省份各个城市的分组,利用首字母作为索引
- UITableVIew实现类似于电话本的首字母索引
- 自定义View 实现字母快速索引控件
- 类似于手机qq空间的下拉tableView上面的图片放大的功能的实现
- 关于使用UILocalizedIndexedCollation 实现tableview的边索引
- Andorid使用自定义View实现通讯录,媒体文件等等的ListView的字母索引
- iOS 类似于礼物说分类栏TableView,CollectionView联动的实现
- 简单实现UITableView索引功能(中英文首字母索引)(一) ByH罗
- Android自定义View——实现联系人列表字母索引
- Android 仿联系人菜单,带字母索引,顶部挤压动画,recyclerview实现联系人页面
- Android 自定义 View 实现通讯录字母索引(仿微信通讯录)
- Android自定义View实现通讯录字母索引(仿微信通讯录)
- 自定义view实现字母索引列表
- iOS UITableView(三) 为tableView添加图片实现电话薄
- Android 自定义 View 实现通讯录字母索引(仿微信通讯录)
- UITableView -- 支持象电话本那样的按首字母索引
- tableview索引添加一个显示点击或滑动到哪个字母的控件