TableView的添加删除执行顺序
来源:互联网 发布:雷洋死亡真相 知乎 编辑:程序博客网 时间:2024/06/06 01:05
1.我们要通过一个控件来控制tableView的编辑状态 进入或者退出编辑状态
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[showTableView setEditing:editing animated:animated];
}
2第二步询问 tableView通过代理方法询问代理 他的每一行Cell是否都能编辑或者不能编辑 我们需要一个编辑状态
#pragma mark———编辑: 添加和删除
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
3.当你的cell被设置成可以编辑状态时 tableView询问你 他到底是添加还是删除 前面都配置好啦 ,当我们点击添加或者删除按钮时,会执行代理方法commitEditingStyle:提交 ,根据tableView 返回样式editingStyle进行区分。
如果删除 如果添加insert
//添加和删除 都执行该代理方法
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//删除
if (editingStyle ==UITableViewCellEditingStyleDelete) {
NSMutableArray *array =[NSMutableArray arrayWithArray:[_dataArray objectAtIndex:indexPath.section]];
if([array count]>1) {
//数据源操作
[array removeObjectAtIndex:indexPath.row];
[_dataArray replaceObjectAtIndex:indexPath.section withObject:array];
//Cell操作
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects: indexPath, nil] withRowAnimation:UITableRowAnimationLeft];
} else {
[_dataArray removeObjectAtIndex:indexPath.section];
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationRight];
}
}
//添加
if (editingStyle == UITableViewCellEditingStyleInsert) {
NSMutableArray *array = [NSMutableArray arrayWithArray:[_dataArray objectAtIndex:indexPath.section]];
[array addObject:@“北京”];
[_dataArray replaceObjectAtIndex:indexPath.section withObject:array];
NSIndexPath * insertIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:insertIndexPath, nil ] withRowAnimation:UITableViewRowAnimationBottom];
}
}
0 0
- TableView的添加删除执行顺序
- iOS中tableview的执行顺序
- ios中tableview的移动添加删除
- tableview添加删除按钮
- tableView代理方法执行顺序
- [ tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationRight ]; 执行的顺序
- tableView的执行先后顺序及主要注意事项
- ios中tableview中的方法的执行顺序
- iOS tableview的delegate和datasource执行顺序
- GridView 删除事件的执行顺序
- Unity 添加脚本后的执行顺序
- vector顺序容器的添加与删除
- tableView的滑动删除
- tableview的滑动删除
- TableView索引的添加
- tableView中动态添加,删除行
- tableView中动态添加,删除行
- iOS tableView删除,添加,排序方法实现
- 使用XStream操作XML和JSON
- 积累(三)
- 数据库存储
- 获取联系人【自定义布局文件与主布局文件相连,数据库内容查找并显示】
- 深入浅出面向对象分析与设计笔记
- TableView的添加删除执行顺序
- 2.Swift教程翻译系列——Swift概览
- WRTNode(MT7620) UBoot 中实现USB功能过程记录
- Oracle SQL性能优化
- 【读书笔记】Windows CE嵌入式系统_【2】_操作系统层
- openSession和getCurrentSession的比较
- 11gR2 grid安装执行root.sh报错
- Question
- 剑指offer面试题34