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)发送相应的消息,最终将得到的数据展示出来
UITableView的常用方法的更多相关文章
- UITableView的常用方法与示例
实例方法 dequeueReusableCellWithIdentifier: 初始化一个指定重用标识符的UITableCell对象 两个协议 UITableViewDataSource tableV ...
- ios学习--TableView详细解释
-.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; [DataTa ...
- UITableView的创建及其一些常用方法
UITableView,它的数据源继承于UITableViewDataSource,它的委托UITableViewDelegate. 一.UITableView的创建 1.代码方式: UITableV ...
- iOS开发-UITableView常用方法
UITableView常用来展示数据,类似于Android中的ListView,相对于Android中的ListView而言,UITableView的实现是非常简单,继承UITableViewData ...
- UITableView详解(1)
一,UITableView控件使用必备,红色部分是易错点和难点 首先创建一个项目,要使用UITableView就需要实现协议<UITableViewDataSource>,数据源协议主要完 ...
- IOS中表视图(UITableView)使用详解
IOS中UITableView使用总结 一.初始化方法 - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)styl ...
- IOS开发之表视图(UITableView)
IOS开发之表视图(UITableView)的基本介绍(一) (一):UITableView的基本概念 1.在IOS开发中,表视图的应用十分广泛和普及.因此掌握表视图的用法显得非常重要.一般情况下对于 ...
- UITableView 协议中常用的方法
UITableViewDataSource 协议中常用方法 1.设置右边 索引值 - ( NSArray *)sectionIndexTitlesForTableView:( UITableView ...
- iOS基础 - UITableView的数据源(dataSource)和代理(delegate)
UITableView的数据源(dataSource)和代理(delegate) UITableView需要一个数据源(dataSource)来显示数据,UITableView会向数据源查询一共有多少 ...
随机推荐
- c# 用正则表达式在指定的字符串中每隔指定个数的文字插入指定字符串
public static string AddNewLine(string inString,int num,string addString="\r\n") { return ...
- ZendStudio10.6.1如何安装最新的集成svn小工具?
选择Help菜单->Install New Software...在Work with输入http://subclipse.tigris.org/update_1.10.x,等待完成后,.除了S ...
- 测试数据库sql声明效率
书写sql当被发现的声明.对于所期望的结果通常是更好地执行. 当面对这些实现的时候如何选择它的最好的,相对来说?这导致了这个博客的话题,如何测试sql效率 以下介绍几种sql语句測试效率的方法,大多数 ...
- AsyncHandler
package com.ango.deskclock; import android.content.Context; import android.content.Intent; import an ...
- php脚本生成google play url的下载链接,下载apk并自动反编译后获取android版本号
需求: get the offer tracking link follow the redirect to get google play url Go to http: ...
- Spring 5 (0) - Introduction & Index
Spring Framework Reference Documentation I. Overview of Spring Framework . Getting Started with Spri ...
- [置顶] think in java interview-高级开发人员面试宝典(二)
从现在开始,以样题的方式一一列出各种面试题以及点评,考虑到我在前文中说的,对于一些大型的外资型公司,你将会面临全程英语面试,因此我在文章中也会出现许多全英语样题. 这些题目来自于各个真实的公司,公司名 ...
- 设计模式16:迭代模式(Iterator)
迭代模式: 它提供了一种方法没有对象的顺序访问聚合对象的暴漏底层的细节. Provide a way to access the elements of an aggregate object seq ...
- quick-cocos2d-x游戏开发【5】——创建菜单
一个菜单是游戏中的一个基本要素,quick在里面menuItem有两个包.一个是图片菜单.一个文本菜单. 一个.图片菜单ui.newImageMenuItem(params) 參数: image: 正 ...
- windows(64位)下用vagrant+virtualbox 管理虚拟机具体解释
windows下安装(64位) vagrant 跟 vituriebox http://blog.smdcn.net/article/1308.html Host: 127.0.0.1 Port: 2 ...