iOS tableView删除,添加,排序方法实现
来源:互联网 发布:js rsa加密 php解密 编辑:程序博客网 时间:2024/05/22 07:03
这里的删除方式有两种,一种是滑动删除,一种是点击"-"号删除按钮再删除。
将下面的注释去掉后实现的是点击按钮删除,未去掉的情况下是滑动删除。
注意下面的list数组是可变数组哦!
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId =@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if(cell == nil){
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellId];
}
cell.textLabel.text = [listobjectAtIndex:indexPath.row];
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [listcount];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//没有实现该方法的时候,默认是滑动删除的
//决定单元格编辑状态
//-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
// //return action == 0 ? UITableViewCellEditingStyleDelete :
// // UITableViewCellEditingStyleInsert;
//}
//删除指定行时指定的确认文本
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return@"确定删除";
}
//DataSourse协议,决定某行是否可以编辑
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row ==0){
return NO;
}else{
return YES;
}
return YES;
}
//DataSourse协议,移动完成时激发该方法
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
NSInteger originRow = sourceIndexPath.row;
NSInteger destRow = destinationIndexPath.row;
id target = [listobjectAtIndex:originRow];
[listremoveObjectAtIndex:originRow];
[listinsertObject:target atIndex:destRow];
}
//编辑(包括删除或插入)完成时激发该方法
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle ==UITableViewCellEditingStyleDelete) {
NSInteger originRow = indexPath.row;
[listremoveObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}elseif(editingStyle ==UITableViewCellEditingStyleInsert){
//在当前行的下一行插入数据
[listinsertObject:[listobjectAtIndex:indexPath.row]atIndex:(indexPath.row +1)];
[tableView insertRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- iOS tableView删除,添加,排序方法实现
- ios中tableview的移动添加删除
- IOS TableView 左滑动删除Cell方法
- IOS 列表删除数据,添加数据,列表排序实现
- IOS 实现多种分类 添加删除排序功能(LXReorderableCollectionViewFlowLayout)
- tableview添加删除按钮
- iOS疯狂详解之tableview编辑添加删除
- 实现添加删除排序修改
- ios tableview 插入删除
- ios tableView删除行
- iOS tableview 滑动删除
- iOS tableview 滑动删除
- ios tableview 删除按钮
- iOS 使用cell的删除功能,实现tableview的代理
- iOS UITableView(三) 为tableView添加图片实现电话薄
- iOS 竖向tableView上添加横向tableView
- TableView编辑中实现多行删除方法以及注意
- swift-tableView 代理方法实现点击按钮删除效果
- 抽屉原理
- xcode如何去掉编译过期警告
- Android 菜单(OptionMenu)大全
- 更多关于z-index
- C#全角和半角转换
- iOS tableView删除,添加,排序方法实现
- play!framework新手安装
- 并查集 路径压缩(详解)
- Android中WindowManager.LayoutParams类详解
- Android GUI之View绘制流程
- gdb 多线程调试
- 关于Linq
- android电池驱动(一)(自用)
- 并查集之经典题型之“食物链”,(偏移向量)