UITableVIew实现类似于电话本的首字母索引
2015-05-23 11:51
447 查看
UITableVIew实现类似于电话本的首字母索引
实际上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];
}
相关文章推荐
- UITableVIew实现类似于电话本的首字母索引
- UITableVIew实现类似于电话本的首字母索引
- TableVIew实现类似于电话本的首字母索引
- Android自定义View实现通讯录字母索引(仿微信通讯录)
- iOS开发 实现字母索引最快捷方法
- 快速集成android实现listview的字母A-Z排序,界面侧边字母索引
- Android实现侧边栏按字母索引
- [转]android实现分组字母索引显示的listview
- 联系人字母索引实现
- Android开发之仿联系人界面(根据文字首字母A、B、C实现快速索引)
- Qt qml 实现类似手机电话薄联系人首字母查找
- Vue + better-scroll 实现移动端字母索引导航功能
- Android实现通讯录功能,排序+字母索引
- Android 仿美团大众字母索引实现
- Andorid使用自定义View实现通讯录,媒体文件等等的ListView的字母索引
- android实现分组字母索引显示的listview
- android实现分组字母索引显示的listview
- 自定义View 实现字母快速索引控件
- 一步一步实现字母索引导航栏
- android中实现更溜的字母导航索引