相信做过iOS的程序员,最熟悉的控件一定少不了UITableView,最常用的控件也一定少不了UITableView!

今天分享一下自己对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

最新文章

  1. SQL高性能查询优化语句(总结)
  2. linux命令:less
  3. Cellphone Typing 字典树
  4. 1.前端笔记之html
  5. c#代码画图
  6. c#中struct和class的区别 详细[转]
  7. SQL Server 之 在与SQLServer建立连接时出现与网络相关的或特定于实例的错误
  8. CentOS 恢复 rm -rf * 误删数据(转)
  9. MIT 三课程
  10. 利用HTTP-only Cookie缓解XSS之痛
  11. 《javascript设计模式与开发实践》阅读笔记(13)—— 职责链模式
  12. [Swift]LeetCode145. 二叉树的后序遍历 | Binary Tree Postorder Traversal
  13. Phone 3rd Recovery
  14. MVC4 decimal 精度
  15. QML学习笔记(七)— 实现可拖拽、编辑、选中的ListView
  16. 【模拟】[NOIP2014]螺旋矩阵[c++]
  17. (Java)入门训练 斐波那契数列
  18. cmd 修改文件或目录的执行权限
  19. 如何用新安装的jdk替换掉Linux系统默认jdk
  20. 把源码放到服务器部署webservice调用出错 MVC C#

热门文章

  1. Win7配置express4环境
  2. pm2命令管理启动的nodejs项目进程
  3. Verilog_Day3
  4. WPF Prism MVVM 中 弹出新窗体. 放入用户控件
  5. APP产品设计流程图
  6. Kotlin的密封(Sealed)类:超强的枚举(KAD 28)
  7. 使用Python客户端(redis-py)连接Redis--华为云DCS for Redis使用经验
  8. php redis和java混用问题
  9. tensorflow学习笔记(3)前置数学知识
  10. SpringCloud IDEA 教学 (一) Eureka的简介与服务注册中心的建立