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. Codeforces Round #306 (Div. 2) D.E. 解题报告

    D题:Regular Bridge 乱搞. 构造 这题乱搞一下即可了.构造一个有桥并且每一个点的度数都为k的无向图. 方法非常多.也不好叙述.. 代码例如以下: #include <cstdio ...

  2. Swift - 创建并设置背景(SpriteKit游戏开发)

    1,先把背景图片bg.jpg,bg@2x.jpg直接拖进Images.xcassets中 2,设置如下代码(背景图直接铺满整个屏幕) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  3. jsp和serverlet的差别

    開始找工作面试的第一家公司,爱思创新 面试题: 1.jsp和serverlet的差别 简单来说: jsp:是包括java程序片的html文件servlet:是包括html的java文件 事实上说白了J ...

  4. access数据库:怎么直接从access里把数据里同样的文字替换成空字符&quot;&quot;

    access数据库:怎么直接从access里把数据里同样的文字替换成空字符"" 搜所到文字后,替换的项里写"",就是了.一定要是英文的""

  5. Lazy Math Instructor

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3721   Accepted: 1290 Description A m ...

  6. DotNetBar.Bar控制Y顺序控制方向

    DotNetBar.Bar控件Y方向上的顺序控制 老帅       控件DevComponents.DotNetBar.Bar是能够有多种用途的.能够作为容器,也能够作为工具条,不管做什么,在Y方向上 ...

  7. java学习之路----内存的分析

    java内存分析           在java中,java语言对程序员做了一个美好的承诺,就是程序员无需去管理内存,因为有GC,其实不然;                      1.垃圾回收并不 ...

  8. VC 绘图技巧--自定义形状图形

    自定义形状图形,定义几个点围城的图形,然后进行描边和填充: if (m_memDC.m_hDC!=NULL) { CPoint point[4]; point[0].x=nLeft+(int)(0.1 ...

  9. MFC-消息分派

    前言 由于工作需要,这几天学了一点MFC,在AFX里看到很多熟悉的东西,如类型信息,序列化,窗口封装和消息分派.几乎每个界面库都必须提供这些基础服务,但提供的手法却千差万别.MFC大量地借用了宏,映射 ...

  10. Oracle dump 分析secondary key

    验证secondary key 含有主键列数据 SQL> select object_name,object_id,OBJECT_TYPE from user_objects; OBJECT_N ...