UITableView中Cell和section的插入与删除
插入段:
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
插入行:
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
如果在编辑模式下,复写此方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
if (indexPath.row == ) {
[self.modeInfomation removeObjectAtIndex:indexPath.section];
[self.modeNameArr removeObjectAtIndex:indexPath.section];
NSIndexSet *sectionIndex = [NSIndexSet indexSetWithIndex:indexPath.section];
[self.tableView deleteSections:sectionIndex withRowAnimation:UITableViewRowAnimationLeft];
}
else {
[[self.modeInfomation objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
在普通模式下:
[self.tableView beginUpdates];
[[self.modeInfomation objectAtIndex:tag] addObject:@"hehe"];
NSIndexPath *indexpath = [NSIndexPath indexPathForRow:row + inSection:tag];
[self.tableView insertRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
注意:
插入或者删除行或段,先更新datasource,再insertRows或insertSections!两个都要更新!
UITableView中Cell和section的插入与删除的更多相关文章
- UITableView中cell里的UITextField不被弹出键盘挡住
UITableView中cell里的UITextField不被弹出键盘挡住 本人视频教程系类 iOS中CALayer的使用 效果如下: 源码: EditCell.h 与 EditCell.m // ...
- UITableView中cell点击的绚丽动画效果
UITableView中cell点击的绚丽动画效果 本人视频教程系类 iOS中CALayer的使用 效果图: 源码: YouXianMingCell.h 与 YouXianMingCell.m / ...
- 如何获取UITableView中cell的frame值
如何获取UITableView中cell的frame值 这个可以用来处理UITableView弹出键盘的问题 本人视频教程系类 iOS中CALayer的使用 效果: 源码: // // ViewC ...
- 用适配器模式处理复杂的UITableView中cell的业务逻辑
用适配器模式处理复杂的UITableView中cell的业务逻辑 适配器是用来隔离数据源对cell布局影响而使用的,cell只接受适配器的数据,而不会与外部数据源进行交互. 源码: ModelCell ...
- iOS学习之UITableView中Cell的操作
接着iOS学习之Table View的简单使用 这篇,这里主要讲UITableView 中的Cell的操作,包括标记.移动.删除.插入. 为了简单快捷,直接从原来那篇的代码开始,代码下载地址:http ...
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
- 解决UITableView中Cell重用机制导致内容出错的方法总结
UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...
- ios UITableView中Cell重用机制导致内容重复解决方法
UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...
- iOS解决UITableView中Cell重用带来的问题
tableView的常规配置,当超出一屏的cell就会标上可重用的标识出列到可重用缓存池中,后面再根据可重用标识来到的可重的cell就会和前面显示同样内容. - (UITableViewCell *) ...
随机推荐
- zepto的tap事件的点透问题的几种解决方案
你可能碰到过在页面上创建一个弹出层,弹出层有个关闭的按钮,你点了这个按钮关闭弹出层后,这个按钮正下方的内容也会执行点击事件(或打开链接).这个被定义为这是一个“点透”现象. 以前,我也听到过tap的点 ...
- Pixar Shorts 皮克斯动画短片全集
[原创短片](Theatrical Shorts)16部 <安德鲁和威利冒险记><顽皮跳跳灯><红色的梦><锡铁小兵><小雪人大行动>< ...
- getPos,offsetTop
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- backbone学习笔记一
backbone是一个MVC单页面框架,针对传统的WEB开发B/S架构的缺点,即通过表现层的浏览器,功能层的WEB服务器,数据层的数据库服务器构架,而操作渲染过程太过复杂.
- 注入语句详解(get注入,cookie注入,搜索型注入等)
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''=' 拆半法 ###################################### and exists (select ...
- U3D--常用属性(不完整,待加)
1. AddComponentMenu 描述:这个属性可以在Component这个菜单栏下加自己定义的子菜单,这样可以快速添加常用的脚本.该属性要用在类上. using UnityEngine; us ...
- TFTP服务
$ mkdir /tftpboot$ cp exynos4412-fs4412.dtb uImage /tftpboot$ sudo chmod 777 tftpboot(~下)$ sudo chmo ...
- Android课程---帧布局 FrameLayout
帧布局的特点是: 1.多个组件,层叠显示 2.所占位置和大小由组件决定 示例代码: <?xml version="1.0" encoding="utf-8" ...
- Print all nodes at distance k from a given node
Given a binary tree, a target node in the binary tree, and an integer value k, print all the nodes t ...
- P4 前端编译器p4c-bm、后端编译器bmv2命令安装 make error问题
参考:Github 安装p4c-bm: sudo pip install -r requirements.txt sudo pip install -r requirements_v1_1.txt / ...