zoukankan      html  css  js  c++  java
  • iOS- 显示数据列表最常用的一个控件UITableView

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

    今天分享一下自己对UITableView的实现大体思路,和整理出来的学习笔记!

    1.UITableView里的结构图                       

    2.UITableView数据展示的条件                      

    1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITableViewdataSource数据源对象

    2> 要想当UITableViewdataSource对象,必须遵守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

  • 相关阅读:
    linux driver ------ 交叉工具链(cross toolchain)
    Qt ------ 截图、获取鼠标指定的RGB值
    Qt ------ QWidget 自定义子类使用信号与槽(Q_OBJECT)后 stylesheet 失效
    Qt error ------ incomplete type 'QApplication' used in nested name specifier
    Qt ------ Q_UNUSED
    SpringCloud 组件Eureka参数配置项详解
    过滤器(Filter)与拦截器(Interceptor)的区别
    事务隔离级别
    事务四大特性
    get与post的区别
  • 原文地址:https://www.cnblogs.com/qingche/p/3553310.html
Copyright © 2011-2022 走看看