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 *) ...
随机推荐
- spring mvc+mybatis+多数据源切换
spring mvc+mybatis+多数据源切换,选取oracle,mysql作为例子切换数据源.oracle为默认数据源,在测试的action中,进行mysql和oracle的动态切换. web. ...
- petapoco定制,比较SQL事务,存储过程,分布式事务(MSDTC)的区别和场景
使用分布式事务时 就锁死了,而且是只锁编辑的行 使用.netSQL事务一定要执行了一个CUD的SQL才会锁死,而且也是锁行,但是也锁读的行 .netSQL事务要在这里才锁死 结论,对于产品要求细粒度的 ...
- Number Sequence
Number Sequence A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) ...
- 纯css3绘制扇形
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- CSS3两个动画顺序衔接播放
问题描述: 第一个动画先播放,播放完成后,第二个动画紧接着播放. 解决办法: 1. 将第二个的延迟时间(animation-delay) 设置成第一个的持续时间( animation-duration ...
- 内置函数----整理、例题 、xmin
-----------数值函数 ---绝对值 select abs(-123) from dual; --求模 select mod (12,5) from dual; --取整 --上限值 sele ...
- php 将查询出的数组数据存入redis
我们从数据库查询出来的数据一般为数组的形式, 而redis是不支持存入数组的, 一种解决办法是将数组转化为json数据,再将json存入redis,之后取出时再将json转化为php数组. 但将取出的 ...
- Git分布式项目管理 入门到学会
Git简介 Git是什么? Git和SVN一样都是一种高效的管理代码的系统. Git是目前世界上最先进的分布式版本控制系统(没有之一). 创建版本库 什么是版本库呢?版本库又名仓库,英文名reposi ...
- BizTalk动手实验(十六)EDI-AS2解决文案开发配置
1 课程简介 通过本课程熟悉EDI.AS2解决文案的开发与配置,本动手实验步骤及内容采用微软官方SDK完成,学员在实验过程中结合官方教程来完成本实验 本实验基于BizTalk 2013(Windows ...
- IOS网络第二天 - 01-基本的HTTP请求
***************** #import "HMViewController.h" #import "MBProgressHUD+MJ.h" @int ...