(十二)UITableView的基本使用
来源:互联网 发布:魔兽中机械宠物矩阵 编辑:程序博客网 时间:2024/05/21 17:25
UITableView之所以支持滚动,是因为继承自UIScrollView。默认是垂直滚动,性能极佳。
UITableView的两种样式:
1.UITableViewStylePlain 例如通讯录的视图。
2.UITableViewStyleGrouped 分组样式,例如微信的发现视图。
如何在TableView上显示数据:
需要通过一个数据源(dataSource)来展示数据。UITableView会向数据源发送消息查询一共有多少行数据以及每一行显示什么内容。
第一步:遵循数据源的protocol,并且设置tableView的数据源为自身:
可以通过拖线绑定dataSource,也可以通过self.tableView.dataSource=self;设定TableView的数据源为控制器。
@interface ViewController () <UITableViewDataSource>
self.tableView.dataSource = self;第二步:重写protocol中规定的一些方法,来告诉TableView分几组,每组显示多少数据,以及在对应的组和行显示什么样的数据。
在TableView中,用section表示组,row表示行,这两个数据合起来称为indexPath,从而实现定位。
1. numberOfSectionsInTableView: 方法用来返回一共显示多少个section(多少组)。
2. tableView: numberOfRowsInSection: 方法用来返回相应的section有多少行(传入参数section,传出参数row)。
3 .tableView: cellForRowAtIndexPath: 方法用来返回相应行的一个数据Cell,Cell即为一行的内容,传入参数indexPath可以唯一确定当前的位置。
调用顺序:先调用1知道组数section,然后调用2一共section次知道每一组有多少数据,最后调用section*对应的组的行数次的3得到每一行应该显示的内容。
Tip:为了分组显示,要将TableView的Style设置成Group类型。
为了协调表格中数据的多样性,一般用模型来存储数据。
设置TableView的头部标题(概括这一组所讲的内容)和尾部标题(用来详细描述这一组怎么用):
使用方法:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ //根据section返回相应的头标题}- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ //根据section返回相应的尾标题}
- (十二)UITableView的基本使用
- UITableView的基本使用
- UITableView 的基本使用
- UITableView 的基本使用
- UITableView的基本使用(一)
- UITableView的基本使用(二)
- UITableView的基本使用一
- iOS UITableView的基本使用
- Swift-UITableView的基本使用
- UITableView的基本使用二(性能优化)
- UITableView的基本使用三(自定义Cell)
- swift地图定位(十二)大头针的基本使用
- UITableView 的基本使用的介绍
- 第二十一篇:UITableView的基本使用
- 十二、oc中autorelease的基本使用
- UITableView 基本使用
- UITableView基本使用
- 5.UITableView基本使用
- 计算机网络(2)——电路交换 报文交换 分组交换
- matlab中如何创建使用构架数组?
- hdu 5106 同余定理+组合数学+快速幂
- 初识Servlet和JSP
- Linux快捷键
- (十二)UITableView的基本使用
- No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom
- Maven的POM详解(三)
- 2015年2月5号工作日志----------------赵鑫
- 工作日志
- MPlayer编解码开发指导
- Android属性动画完全解析(上),初识属性动画的基本用法
- 例题8-4 传说中的车 UVa11134
- ubuntu 网络设置