先上图,大家看看效果
原理:
1、从数据中获取的通讯录信息存入NSMutableArray中
2、将姓名进行拼音化处理,按顺序排序,并将首字母相同的数组以首字母为关键字存放到NSMutableDectionary中
排序方法用的是NSSortDescriptor中的sortDecriptorWithKey:方法
3、利用UITableview中的方法进行实现。主要是实现这五个方法:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;//绘制表格右侧索引
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;//指定有多少个分区
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;//显示列表分组头名
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;//确定每个分区有多少行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;//绘制Cell