UITableView(二编辑删除)
来源:互联网 发布:淘宝和天猫京东哪个好 编辑:程序博客网 时间:2024/05/16 17:53
1.删除行
首先创建编辑按钮
UIBarButtonItem * right = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:(UIBarButtonItemStylePlain) target:self action:@selector(didClickRightBarButtonItemAction:)];
-(void)didClickRightBarButtonItemAction:(UIBarButtonItem *)button{ NSLog(@"%@",button); // _isEditing = !_isEditing; if (_isEditing) { NSLog(@"bianji = %d",_isEditing); _isEditing = NO;//没有进入编辑状态 button.title = @"编辑"; }else{ NSLog(@"wanc = %d",_isEditing); _isEditing = YES;//进入编辑状态 button.title = @"完成"; } //tableView进入编辑状态 //默认所有的行都可以被编辑,编辑样式默认都是删除 [_listTableView setEditing:_isEditing animated:YES];}
//是否可以编辑,当某一行可以删除时才出现-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ //当没有分区时编辑不执行 if (indexPath.section ==0) { return NO; } return YES;}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { // NSLog(@"%s,%d",__FUNCTION__,__LINE__); //修改数据源,即删除数据源中的某条数据 NSMutableArray * oneGoupArray = [_allGroupArray objectAtIndex:indexPath.section]; //如果删除某行cell,cell刚好是section最后一条数据时不再删除cell,直接删除section if (oneGoupArray.count == 1) { //删除section NSLog(@"indexPath = %ld",indexPath.section); [_allGroupArray removeObjectAtIndex:indexPath.section]; NSLog(@"indexPath2 = %ld",indexPath.section); [_listTableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationRight]; NSLog(@"indexPath3 = %ld",indexPath.section); }else{ [oneGoupArray removeObjectAtIndex:indexPath.row]; //tableview删除某行 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationRight]; } }}
0 0
- UITableView(二编辑删除)
- UITableView 添加,删除,编辑
- UITableView(二编辑插入)
- UITableView(二编辑移动)
- UITableView 自带编辑删除
- UITableview 去除滑动删除 编辑状态删除
- UITableView实现删除移动编辑的样式
- UITableView 自带编辑删除 自定义按钮
- UITableView 自带编辑删除 自定义按钮
- UItableView中编辑,删除,移动学习笔记
- UITableView 编辑状态(删除、添加、移动)
- UITableView-编辑模式(多选移动删除)
- UITableView基本属性二:编辑模式
- 编辑UITableView
- UITableView编辑
- UITableView编辑
- UITableView编辑
- UITableView编辑
- 記憶的遙遠
- 【C语言复习(二十六)】各个目标文件的关系
- 迭代器 与泛型for
- scala入门2(简介与基础语法2--数值类型)
- XML解析之DOM4J
- UITableView(二编辑删除)
- 黑马程序员-java多线程
- maven中央仓库地址,什么jar包多可以搜到
- 未能加载类型
- 如何将Sql server数据库中的模型图转化到Word中--并能够查看字段的属性信息
- XtraBackup备份原理图解
- 视频面试
- ARM处理器学习之--GPIO操作篇(gnu link script)
- 快速掌握一个语言最常用的50%