ios UITableView 相关
1、tableView 实现的方法 无分组的cell
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.contacts.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.创建cell
MJContactCell *cell = [MJContactCell cellWithTableView:tableView]; // 2.设置cell的数据
cell.contact = self.contacts[indexPath.row]; return cell;
}
2、tableView的刷新:
* 局部刷新(使用前提: 刷新前后, 模型数据的个数不变)
- (void)reloadRows:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
3、* 局部删除(使用前提: 模型数据降低的个数 == indexPaths的长度)
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
4、tableview 在storyboard 创建的时候 假设tableview中的cell是写死的,当自己定义controller关联的时候 要记得删掉数据源中的方法, numberOfRowsInSection 方法等
左滑动会调用 commitEditingStyle 方法 commitEditingStyle 中须要推断是 加入还是删除
#pragma mark - tableView的代理方法
/**
* 假设实现了这种方法,就自己主动实现了滑动删除的功能
* 点击了删除button就会调用
* 提交了一个编辑操作就会调用(操作:删除\加入)
* @param editingStyle 编辑的行为
* @param indexPath 操作的行号
*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) { // 提交的是删除操作
// 1.删除模型数据
[self.contacts removeObjectAtIndex:indexPath.row]; // 2.刷新表格
// 局部刷新某些行(使用前提:模型数据的行数不变)
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop]; // 3.归档
[NSKeyedArchiver archiveRootObject:self.contacts toFile:MJContactsFilepath];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// 1.改动模型数据
MJContact *contact = [[MJContact alloc] init];
contact.name = @"jack";
contact.phone = @"10086";
[self.contacts insertObject:contact atIndex:indexPath.row + 1]; // 2.刷新表格
NSIndexPath *nextPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[nextPath] withRowAnimation:UITableViewRowAnimationBottom];
// [self.tableView reloadData];
}
}
// 让tableView进入编辑状态
[self.tableView setEditing:!self.tableView.isEditing animated:YES];
当实现editStyleForRowAtIndexPath 的是时候,当点击编辑的时候就会调用此方法,此方法是询问编辑的状态的
/**
* 当tableView进入编辑状态的时候会调用,询问每一行进行如何的操作(加入\删除)
*/
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return indexPath.row %2 ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleInsert;
}
ios UITableView 相关的更多相关文章
- iOS UITableView划动删除的实现
标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...
- iOS UITableView优化
一.Cell 复用 在可见的页面会重复绘制页面,每次刷新显示都会去创建新的 Cell,非常耗费性能. 解决方案:创建一个静态变量 reuseID,防止重复创建(提高性能),使用系统的缓存池功能. s ...
- iOS网络相关知识总结
iOS网络相关知识总结 1.关于请求NSURLRequest? 我们经常讲的GET/POST/PUT等请求是指我们要向服务器发出的NSMutableURLRequest的类型; 我们可以设置Reque ...
- UITableView相关知识点
//*****UITableView相关知识点*****// 1 #import "ViewController.h" // step1 要实现UITableViewDataSou ...
- iOS网络相关零散知识总结
iOS网络相关零散知识总结 1. URL和HTTP知识 (1) URL的全称是Uniform Resource Locator(统一资源定位符). URL的基本格式 = 协议://主机地址/路径 ...
- IOS UITableView NSIndexPath属性讲解
IOS UITableView NSIndexPath属性讲解 查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...
- iOS UITableView Tips(2)
#TableView Tips(2) (本来想一章就结束TableView Tips,但是发现自己还是太天真了~too young,too simple) ##架构上的优化 在Tips(1)中指出了一 ...
- iOS:UITableView相关(18-10-20更)
UITableView用得较多,遇到的情况也较多,单独记录一篇. 一.零散的技巧 二.取cell 三.cell高度 四.导航栏.TableView常见问题相关 五.自定义左滑删除按钮图片 六.仅做了解 ...
- iOS开发,UITableView相关问题
第一条:UITableViewCell 内容的设置 //文本放到最后 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_dataArr.co ...
随机推荐
- Java中怎么控制线程訪问资源的数量
在API中是这样来描写叙述Semaphore 的 Semaphore 通经常使用于限制能够訪问某些资源(物理或逻辑的)的线程数目. 一个计数信号量.从概念上讲,信号量维护了一个许可集.如有必要,在许可 ...
- Oracle误删除表数据后的恢复具体解释
Oracle误删除表数据后的恢复具体解释 測试环境: SYSTEM:IBM AIX 5L Oracle Version:10gR2 1. undo_re ...
- MSSQL- select @@identity的用法
转载自:http://blog.163.com/zhangqian_sms/blog/static/544483382008925112539620/ 用select @@identity得到上一次插 ...
- Redis核心解读:集群管理工具(Redis-sentinel)
Redis核心解读:集群管理工具(Redis-sentinel) - Redis - TechTarget数据库 Redis核心解读:集群管理工具(Redis-sentinel)
- mysql基础:mysql列类型--时间和日期
mysql列类型--整型 http://blog.csdn.net/jk110333/article/details/9342283 mysql列类型--字符串http://blog.csdn.net ...
- [积累]C++复习 海大2014硕士生面试题微信系统总结
好久没用C++了,正好同学有个面试题,于是就帮忙看了一下.尽管对C++的知识了解不少, 可是长期被Java浸淫, 发现这个简单的程序却也写着也不是那么顺手.好在最后还是搞定了,以下分析一下,题目例如以 ...
- Android调用系统相机、自己定义相机、处理大图片
Android调用系统相机和自己定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,而且因为涉及到要把拍到的照片显示出来,该样例也会涉及到Android载入大图片时候的处 ...
- Linux内核参数信息(Oracle相关)
命令行:vim /etc/sysctl.conf 查看如下两行的设置值,这里是: kernel.shmall = 2097152 kernel.shmmax = 4294967295 如果系统默认的 ...
- hdu 2147 SG函数打表(手写也可以) 找规律
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others) Total ...
- HDU 3549 Flow Problem(有向边网络流)
九野的博客,转载请注明出处 :http://blog.csdn.net/acmmmm/article/details/11221561 题意:T个测试数据 下面n,m表示n个点m条有向带权边 m条边 ...