iOS- 显示数据列表最常用的一个控件UITableView
2014-02-17 22:03
239 查看
相信做过iOS的程序员,最熟悉的控件一定少不了UITableView,最常用的控件也一定少不了UITableView!
今天分享一下自己对UITableView的实现大体思路,和整理出来的学习笔记!
2> 要想当UITableView的dataSource对象,必须遵守UITableViewDataSource协议,实现相应的数据源方法
3> 当UITableView想要展示数据的时候,就会给数据源发送消息(调用数据源方法),UITableView会根据方法返回值决定展示怎样的数据
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
得知一共有多少组
2> 然后调用数据源的
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
得知第section组一共有多少行
3> 然后调用数据源的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
得知第indexPath.section组 第indexPath.row 行显示怎样的cell(显示什么内容)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@required 2.3 是必须实现
2> 第section组一共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
3> 第indexPath.section组 第indexPath.row行显示怎样的cell(显示什么内容)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
4> 第section组显示怎样的头部标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
5> 第section组显示怎样的尾部标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
选中了UITableView的某一行
2.- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
某一行的高度
3.- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
第section分区头部的高度
4.- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
第section分区尾部的高度
5.- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
第section分区头部显示的视图
6.- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
第section分区尾部显示的视图
7.- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
设置每一行的等级缩进(数字越小,等级越高)
2> 刷新表格
- reloadData
整体刷新(每一行都会刷新)
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
局部刷新
清澈Saup
今天分享一下自己对UITableView的实现大体思路,和整理出来的学习笔记!
1.UITableView里的结构图
2.UITableView数据展示的条件
1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITableView的dataSource数据源对象2> 要想当UITableView的dataSource对象,必须遵守UITableViewDataSource协议,实现相应的数据源方法
3> 当UITableView想要展示数据的时候,就会给数据源发送消息(调用数据源方法),UITableView会根据方法返回值决定展示怎样的数据
3.数据展示的过程
数据显示,三步走
1> 先调用数据源的- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
得知一共有多少组
2> 然后调用数据源的
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
得知第section组一共有多少行
3> 然后调用数据源的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
得知第indexPath.section组 第indexPath.row 行显示怎样的cell(显示什么内容)
4.开发中经常用到的UITableView数据源方法
1> 一共有多少组- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@required 2.3 是必须实现
2> 第section组一共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
3> 第indexPath.section组 第indexPath.row行显示怎样的cell(显示什么内容)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
4> 第section组显示怎样的头部标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
5> 第section组显示怎样的尾部标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
5.开发中经常用到的UITableView代理方法
1.- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath选中了UITableView的某一行
2.- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
某一行的高度
3.- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
第section分区头部的高度
4.- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
第section分区尾部的高度
5.- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
第section分区头部显示的视图
6.- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
第section分区尾部显示的视图
7.- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
设置每一行的等级缩进(数字越小,等级越高)
6.tableView刷新数据的方式
1> 修改模型数据2> 刷新表格
- reloadData
整体刷新(每一行都会刷新)
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
局部刷新
清澈Saup
相关文章推荐
- iOS- 显示数据列表最常用的一个控件UITableView
- VB.Net自己写的一个控件:ComboBox下拉列表中显示多列数据(可以绑定数据表)
- easyUI的列表控件(datagrid)日期列不能正确显示Json格式数据的解决方法
- 微信小程序--(5-1)点击列表item,把item上面显示的所有数据,传递到另外一个页面
- iOS项目开发实战——学会使用TableView列表控件(四)plist读取与Section显示
- [VC/MFC]虚拟列表控件——显示上百万数据的列表控件
- UITableView 分页显示、加载更多,数据源远程数据,解析JSON,以及iOS☞Category
- discuz中写一个表单,数据存入到数据库中,再从数据库读出来显示在列表中
- 解决WinForm中ComboBox控件的“设置"DataSourse”属性后无法修改项集合”以及两个不相关联的ComboxBox控件实现数据列表显示不可实现的问题
- iOS 一个控件内字符显示不同的字体,大小和颜色
- 将多组数据显示在一个控件内
- 【iOS基础控件 - 8 】【demo】 展示团购数据 UITableViewCell <代理,xib封装view>
- iOS项目开发实战——学会使用TableView列表控件(四)plist读取与Section显示
- IOS控件系列----使用UITableView实现网格布局,自定义显示列数
- Flex中如何创建一个自定义数据显示Tips的slider控件。鼠标按住滑标察看效果
- Spring中将一个对象数据显示在前端的列表中
- 将数据库中的数据通过 client 控件显示 (一个asp和javascript传参数的列子)
- 由于以下一个或多个原因,无法在数据表视图中显示列表:
- ASPxGridView控件常用示例五:显示Detail数据
- 介绍一个免费的具备数据显示/录入/更新/删除功能的asp.net控件