iOS索引,按字母排序
来源:互联网 发布:php上传文件原理 编辑:程序博客网 时间:2024/05/21 06:50
table的索引,汽车之家之类那种选车索引。
最主要的就是 sectionIndexTitlesForTableView:(UITableView *)tableView 这个方法;
上代码了
我自己用了一个plist 类似于这种
我附上一个demo,自己看看吧 github上
demo链接
https://github.com/KingOfZhang/SuoYin/tree/master
{
A = (
A1,
A2,
A3,
A4
);
B = (
B1,
B2,
B3,
B4
);
C = (
C1,
C2,
C3,
C4,
C5,
C6
);
}
//// ViewController.m// UISearBar//// Created by 易云时代 on 2017/8/21.// Copyright © 2017年 XW. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{ NSMutableArray *arr; NSDictionary *_dataSource;}@property (nonatomic, strong) UITableView *table;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WITH, SCREEN_HEIGHT) style:UITableViewStyleGrouped]; _table.delegate = self; _table.dataSource = self; [self.view addSubview:_table]; arr = [[NSMutableArray alloc]init]; NSString *path = [[NSBundle mainBundle] pathForResource:@"NameList" ofType:@"plist"]; _dataSource = [NSDictionary dictionaryWithContentsOfFile:path]; NSArray *atttt = [_dataSource allKeys]; atttt = [atttt sortedArrayUsingSelector:@selector(compare:)]; arr = [atttt copy]; [_table reloadData];}#pragma mark TableViewDelegateAndDataSource-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 20;}-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return arr[section];}-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _dataSource.count;}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 30;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pp"]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pp"]; } NSArray *st = [_dataSource objectForKey:arr[indexPath.section]];; cell.textLabel.text = st[indexPath.row]; return cell;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSArray *array = [_dataSource objectForKey:arr[section]]; return array.count;}-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return arr;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
阅读全文
0 0
- iOS索引,按字母排序
- 按字母索引排序listview
- iOS 名字按字母排序
- RecyclerView+侧边字母索引排序
- ios按字母排序的通讯录
- IOS tabview 添加字母索引
- iOS字母排序、数字排序
- iOS 开发 排序问题 (好友列表,按字母排序)
- 按字母索引
- iOS简单排序--字母排序、NSDictionary排序
- Android listview 侧栏字母索引排序
- Android ListView实现分组字母索引排序
- 联系人列表字母排序索引(一)
- 联系人列表字母排序索引(二)
- 联系人列表字母排序索引(三)
- Android实现通讯录功能,排序+字母索引
- IOS数组按中文关键字以字母序排序
- IOS数组按中文关键字以字母序排序
- JavaScript加载速度倍增的方法。
- JQery图片淡入淡出效果案例
- 目录整理
- C++中的虚函数(virtual function)
- CodeFroces 817D Imbalanced Array(单调栈)
- iOS索引,按字母排序
- Spring中@Bean与@Configuration
- 游戏引擎概念----快速了解
- hashmap在初始化的时候直接赋值的方法
- 信息学蒟蒻域ACM模拟赛题解
- 测试ip是否可用(ip代理时)
- LintCode_拓扑排序_BFS实现
- Find the nondecreasing subsequences--(树状数组)
- 我对C++的前景看法 C++和C#的对比