TableView编辑
来源:互联网 发布:彭博数据终端 编辑:程序博客网 时间:2024/05/29 07:36
#pragma mark TableView编辑
#warning 第一步:让tableView处于编辑状态(Warning警告的意思)
- (void)editButton:(id)sender
{
// edit:添加事件
[_tablesetEditing:YESanimated:YES];
}
#warning 第二步:通知tableview哪些cell可以被编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// if (indexPath.row == 0) {
// return YES;
// }
// return NO;
return YES;
}
#warning 第三步:cell的编辑模式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row ==0) {
returnUITableViewCellEditingStyleDelete;
}
returnUITableViewCellEditingStyleInsert;
}
#warning 第四步:提交编辑结果
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//如果做的是删除操作,就把相对应的数组的那一行给删除了
if (editingStyle ==UITableViewCellEditingStyleDelete) {
[_tableArrayremoveObjectAtIndex:indexPath.row];
//
// // 数据源(数组)发生改变,则必须让tableView的所有协议重新再走一遍,告诉tableView关于行数、内容的改变是什么
// // 刷新tableView (最经常用的刷新方式)
// [tableView reloadData];
// 删除单个或多个行 数组中存得就是索要删除的IndexPath
NSArray *array = @[indexPath];
// // 如果没有Index的话,就自己创建(自己创建IndexPath的方法)
// NSIndexPath *myIndex = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView deleteRowsAtIndexPaths:arraywithRowAnimation:UITableViewRowAnimationFade];
}elseif (editingStyle ==UITableViewCellEditingStyleInsert){
StudentModel *s4 = [StudentModelstudentModerWithName:@"老王"gender:@"男"teleNumber:@"15840959355"];
[_tableArrayaddObject:s4];
// [tableView reloadData];
NSIndexPath *myIndex = [NSIndexPathindexPathForRow:[_tableArraycount] - 1 inSection:0];
[tableView insertRowsAtIndexPaths:@[myIndex]withRowAnimation:UITableViewRowAnimationFade];
}
}
#pragma mark -
#pragma mark 移动
// 是否可以移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// [tableView reloadData];
return YES;
}
// 移动sourceIndexPath:将要移动的 destinationIndexPath:目标
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
//先改变数据源的顺序(从数组中拿出来的时候release,所以要先retain)
StudentModel *model = [[_tableArrayobjectAtIndex:sourceIndexPath.row]retain];
[_tableArrayremoveObjectAtIndex:sourceIndexPath.row];
[_tableArrayinsertObject:model atIndex:destinationIndexPath.row];
[tableViewreloadData];
[modelrelease];
}
- TableView编辑
- TableView编辑
- 可编辑的TableView
- 设置TableView可编辑
- tableview 编辑整理
- tableView选中状态编辑
- tableView的编辑模式
- tableView - 编辑模式
- tableView的编辑
- tableview的编辑
- tableView的编辑
- 34.tableView的编辑
- IOS-tableview编辑
- tableView - 编辑模式
- tableView的编辑
- TableView的编辑
- tableView编辑样式设计
- TableView之编辑模式
- java的静态导入和装箱拆箱
- MongoDB介绍及下载与windows下安装
- 持续更新-jQuery发微(三)-H5<video>设置高宽
- 递归函数执行顺序
- GCD 深入理解(一)
- TableView编辑
- http中get和post的方法
- 蓝桥杯 ALGO-92 前缀表达式(水题)
- Alfresco在iis发布的时候出现的问题
- java中可变参数
- 2014 蓝桥杯 预赛 c/c++ 本科B组 第三题:李白打酒 (8' )
- Linux下搭建 PPPoE Server 问题总结
- hadoop2.6.0的编译小结
- Word Break II[动态规划&DFS]