zoukankan      html  css  js  c++  java
  • UITableView的常用方法

    一、UITableView的代理方法

    #pragma mark 每一行的高度
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    
     
    
    #pragma mark 选中了某一行就会调用
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    
     
    
    #pragma mark 取消选中了某一行就会调用
    
    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
    
     
    
    #pragma mark 当用户提交了一个编辑操作就会调用(比如点击了“删除”按钮)
    
    // 只要实现了这个方法,就会默认添加滑动删除功能
    
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    
     
    
    #pragma mark 当移动了某一行cell就会调用
    
    // 只要实现了这个方法,就会默认添加排序功能
    
    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
    

    二、修改Cell的状态

    1.最好通过修改模型数据来修改Cell的状态

    2.修改步骤

    1> 修改模型数据

    2> 刷新表格

    * 整体刷新:reloadData(最重要)

    * 局部刷新:reloadRowsAtIndexPaths:withRowAnimation:

    三、UITableView常见方法

    1.取消选中某一行(去掉cell选中时默认的蓝色背景)

    - (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

    2.局部刷新(仅仅刷新indexPaths数组中装着的行)

    - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

    3.整体刷新(屏幕中的每一行都刷新)

    - (void)reloadData;

    4.直接删除界面上的行数(要求模型数据也要删掉对应的数量)

    - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

    5.设置编辑模式

    @property(nonatomic,getter=isEditing) BOOL editing; 

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated;

    五、UITableView方法补充

    1.如果tableView通过@"Cell"这个标志去缓存池中没有取到可循环利用的Cell,就会加载MyCell1.xib文件来创建cell

    [self.tableView registerNib:[UINib nibWithNibName:@"MyCell1" bundle:nil] forCellReuseIdentifier:@"Cell"];

    2.如果tableView通过@"cell2"这个标志去缓存池中没有取到可循环利用的Cell,就会创建MyCell2对象作为cell

    [self.tableView registerClass:[MyCell2 class] forCellReuseIdentifier:@"cell2"];

    // 注意:

    不管是局部刷新,还是整体刷新,原理都是:

    UITableView重新向数据源(dataSource)和代理(delegate)发送相应的消息,最终将得到的数据展示出来

    如果你错过了一天,那么你就真的错过了一天……ues.hk
  • 相关阅读:
    ensp实验:使用Serial接口
    1146
    Navicat连linux上mysql数据库报错can't connect to mysql server ... 10060
    Bug 23572982,Oracle19c新建pdb受限模式,SYNC PDB FAILED WITH ORA-959 DURING 'CREATE USER
    内核参数限制导致无法su切换登录用户
    模拟测试恢复redhat7.5系统权限
    Oracle-OGG,双向同步过滤OGG自身用户的DML失效,如何处理?
    OGG-Oracle同步Sequence
    Scalable Sequences 学习测试
    OGG-DDL同步报错OGG-00516 ORA-12991: column is referenced in a multi-column constraint]
  • 原文地址:https://www.cnblogs.com/myios/p/3670710.html
Copyright © 2011-2022 走看看