码迷,mamicode.com
首页 > 其他好文 > 详细

UITableView的使用(3)

时间:2016-03-02 21:53:17      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

title: UITableView的使用(3)
tags:
- iOS
- UITableView
categories: iOS

description: 《精通iOS开发》第8章笔记

本文主要讲述UITableView的分组分区和索引分区的使用。

主要通过以下几个方法来实现

先定义两个属性,值从plist文件中取,如下图

//定义两个属性
@property (copy, nonatomic) NSDictionary *names; //以分组标题为key,分组下所有值为value的字典
@property (copy, nonatomic) NSArray *keys; //所有分组的标题

技术分享

实现分组分区

//返回分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return self.keys.count;
}

//返回每个分区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        NSString *key = self.keys[section];
        NSArray *nameSection = self.names[key];
        return nameSection.count;
}

//每个分区头部的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
       return self.keys[section];
}

实现索引分区

//相当于返回每个分区头部标题,索引分区是建立在分组分区之上的,有多少个索引就有多少个分区
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
        return self.keys;
}

完整项目https://github.com/limaofuyuanzhang/iOSLearn/tree/master/08-Sections

UITableView的使用(3)

标签:

原文地址:http://www.cnblogs.com/limaofuyuanzhang/p/iOSLearn83.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!