UITableView的用法还有分组列表,并且有时候还会让我们现实右侧索引。
比如我们的原始数据为包含多个字典的数组,那么我们就要自己根据某个字段进行分类,转换成NSDictionary的形式。
下面举例来说明,比如我们有这样的一组数据源NSArray,根据firstLetter分组,并且现实右侧索引
首先我们要把这组数据转换成以firstLetter的值为key的NSDictionary的形式,代码如下
好,现在我们的数据已经转换成我们想要的形式了,如下图,截图不全,效果看到就好(下面就是 _contactDict的数据)
接下来实现tableView几个重要的方法就可以了
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView//分组数
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath//
还有两个索引的方法,直接上图了
基本上这样就可以了。有问题欢迎提问和指正。谢谢。