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 相关的更多相关文章

  1. iOS UITableView划动删除的实现

    标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...

  2. iOS UITableView优化

    一.Cell 复用 在可见的页面会重复绘制页面,每次刷新显示都会去创建新的 Cell,非常耗费性能.  解决方案:创建一个静态变量 reuseID,防止重复创建(提高性能),使用系统的缓存池功能. s ...

  3. iOS网络相关知识总结

    iOS网络相关知识总结 1.关于请求NSURLRequest? 我们经常讲的GET/POST/PUT等请求是指我们要向服务器发出的NSMutableURLRequest的类型; 我们可以设置Reque ...

  4. UITableView相关知识点

    //*****UITableView相关知识点*****// 1 #import "ViewController.h" // step1 要实现UITableViewDataSou ...

  5. iOS网络相关零散知识总结

    iOS网络相关零散知识总结 1. URL和HTTP知识 (1) URL的全称是Uniform Resource Locator(统一资源定位符). URL的基本格式 = 协议://主机地址/路径   ...

  6. IOS UITableView NSIndexPath属性讲解

    IOS UITableView NSIndexPath属性讲解   查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...

  7. iOS UITableView Tips(2)

    #TableView Tips(2) (本来想一章就结束TableView Tips,但是发现自己还是太天真了~too young,too simple) ##架构上的优化 在Tips(1)中指出了一 ...

  8. iOS:UITableView相关(18-10-20更)

    UITableView用得较多,遇到的情况也较多,单独记录一篇. 一.零散的技巧 二.取cell 三.cell高度 四.导航栏.TableView常见问题相关 五.自定义左滑删除按钮图片 六.仅做了解 ...

  9. iOS开发,UITableView相关问题

    第一条:UITableViewCell 内容的设置 //文本放到最后 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_dataArr.co ...

随机推荐

  1. mysql存储过程及经常使用函数

    一.函数 1.数学函数 CEIL()进一取整 SELECT CEIL(1.2);2 FLOOR()舍一取整 SELECT FLOOR(1.9);9 MOD取余数(取模) SELECT MOD(3,8) ...

  2. boa-0.94.13:Hello CGI

    CGI是什么 CGI全称是CommonGateway Interface,简称CGI,中文名叫做通用网关接口. CGI程序就是符合CGI接口规范的程序,相对于WebServer来说也叫外部程序. CG ...

  3. java中怎么判断一个字符串中包含某个字符或字符串

    public static void main(String[] args) { String str="ABC_001"; ){ System.out.println(" ...

  4. linux kill进程和子进程小trick

           我们的hive web是调用polestar restful service(https://github.com/lalaguozhe/polestar-1)来执行具体的hive或者s ...

  5. 基于visual Studio2013解决面试题之0202上下排

     题目

  6. viewDidLoad、viewDidUnload、viewWillAppear、viewDidAppear、viewWillDisappear 和 -viewDidDisappear的区别和使用

    首先看一下官方解释: - (void)loadView; // This is where subclasses should create their custom view hierarchy i ...

  7. XMPPclient库Smack 4.0.6一个版本的开发

    XMPPclient库Smack 4.0.6版开发之中的一个 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs 一.Smack库概述 Smack是一个开源. ...

  8. hdu1573-X问题

    http://acm.hdu.edu.cn/showproblem.php?pid=1573 中国剩余定理 #include<iostream> #include<cstdio> ...

  9. HDU 1535 Invitation Cards(SPFA,及其优化)

    题意: 有编号1-P的站点, 有Q条公交车路线,公交车路线只从一个起点站直接到达终点站,是单向的,每条路线有它自己的车费. 有P个人早上从1出发,他们要到达每一个公交站点, 然后到了晚上再返回点1. ...

  10. 轻松学会多线程(四)——synchronized同步keyword知多少

    每个对象都有一把独占锁. 独占锁仅仅限制线程对它的同步方法的訪问,对非同步方法,独占锁没有意义. synchronizedkeyword能够作为函数的修饰符,也能够作为函数内的语句,也就是平时说的同步 ...