【UITableView】UITableView 编辑
来源:互联网 发布:长沙淘宝主播招聘 编辑:程序博客网 时间:2024/05/17 20:22
//某一行是否可以移动- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPatt{ return NO;}
//确认移动- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{ if(sourceIndexPath.section == destinationIndexPath.section){ //获取要移动元素所在的组(子数组) NSMutableArray *subArray = [_dataArray objectAtIndex:sourceIndexPath.section]; //获得要移动的对象 DataItem *item = [subArray objectAtIndex:sourceIndexPath.row]; //删除 [subArray removeObject:item]; //将他插入到新位置 [subArray insertObject:item atIndex:destinationIndexPath.row]; }else{ //获得要移动的对象 NSMutableArray *subArray = [_dataArray objectAtIndex:sourceIndexPath.section]; DataItem *item = [subArray objectAtIndex:sourceIndexPath.row]; [subArray removeObject:item]; //获得目标数组 NSMutableArray *destArray = [_dataArray objectAtIndex:destinationIndexPath.section]; //插入新元素 [destArray insertObject:item atIndex:destinationIndexPath.row]; }}
//编辑方式 删除或者插入- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row%2!=0){ return UITableViewCellEditingStyleInsert; } return UITableViewCellEditingStyleDelete;}
//是否可以编辑(默认是可以编辑的)- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;//indexPath.row%2==0;}
//确认编辑的方法- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if(editingStyle == UITableViewCellEditingStyleInsert){ NSMutableArray *subArray = [_dataArray objectAtIndex:indexPath.section]; DataItem *oldItem = [subArray lastObject]; NSRange range =[oldItem.title rangeOfString:@":"]; NSString *replaceStr = [oldItem.title substringFromIndex:range.location]; DataItem *item = [[DataItem alloc]init]; item.title = [oldItem.title stringByReplacingOccurrencesOfString:replaceStr withString:[NSString stringWithFormat:@"%d行",[subArray count]]]; item.state = 0; [subArray insertObject:item atIndex:indexPath.row]; [_myTalbelView reloadData]; }else { NSMutableArray *subArray = [_dataArray objectAtIndex:indexPath.section]; [subArray removeObjectAtIndex:indexPath.row]; //刷新界面(必须加这句,不然点删除删不了) [_myTalbelView reloadData]; }}
//索引对应关系- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ return (index+2)%26;}
//删除样式- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row%4==0){ return @"删除"; } return @"Remove";}
0 0
- 【UITableView】UITableView 编辑
- 编辑UITableView
- UITableView编辑
- UITableView编辑
- UITableView编辑
- UITableView编辑
- UITableVIew 编辑
- UITableView 编辑
- UITableView 添加,删除,编辑
- UITableView编辑模式
- UITableView编辑模式
- UITableView编辑模式详解
- UITableView编辑模式
- UITableView编辑模式
- UITableView编辑模式
- UITableView编辑模式
- UITableView编辑模式
- UItableview编辑模式
- nginx php
- 一个JSP页面导致的tomcat内存溢出
- 黑马程序员-day13-基本数据类型对象包装类
- java与shell脚本互调
- 黑马程序员 java学习笔记(day02)
- 【UITableView】UITableView 编辑
- Memcached常用命令及使用说明
- 深入理解 AngularJS 的 Scope
- 老师布置的C++实践作业:C++编写的学生系统
- 多叉树非递归遍历
- sublime text如何安装ctags来定位函数
- tolua++快速将我们自定义的c2dx类嵌入,供 lua脚本使用
- Generating a string with elements from an array based on pattern matching
- MySQL 5.1 C API