ios tableView那些事 (九) tableview的删除
来源:互联网 发布:天人网络电视官网 编辑:程序博客网 时间:2024/05/23 19:19
http://blog.csdn.net/lengshengren/article/details/10742993
这孩纸好多tableview的用法总结,挺不错的。
tableview 的删除一定是很常用的在应用里! 在应用里大多会用到3中删除方式!
第一种滑动方式,在cell 的最右边向右滑动cell ,默认的删除是汉字,我们先改下语言吧!怎么也的改成国语!
这是常用的方式!也是必须用到的方式
上一章我们设置了不出现红色按钮
下面设置可以出现删除按钮 或者直接不写这个方法
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
/*改变删除按钮的title*/
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
/*删除用到的函数*/
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.arrayValue removeObjectAtIndex:[indexPath row]]; //删除数组里的数据
[tableview deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; //删除对应数据的cell
}
}
第二中是在导航栏上加个删除按键!为了有的用户不知道删除手势!这样也更加明了
就像上一章插入的方式一样! 只要让tableview可以编辑就会出现删除按钮
UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]initWithTitle:@"管理" style:UIBarButtonItemStyleBordered target:selfaction:@selector(deleteAction)];
-(void)deleteAction
{
[self.tableview setEditing:!self.tableview.editing animated:YES];
if (self.tableview.editing)
{
[self.navigationItem.leftBarButtonItem setTitle:@"删除"];
}
else
{
[self.navigationItem.leftBarButtonItem setTitle:@"管理"];
}
}
效果如下
第三种是在一个前辈博客rainbird.blog 中学到的一种批量删除方法!
deleteDic = [[NSMutableDictionary alloc]init];
UIBarButtonItem *delBtn = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:selfaction:@selector(delbtnClick)];
UIBarButtonItem *editBtn = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleBordered target:selfaction:@selector(editbtnClick)];
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
//删除按钮
-(void)delbtnClick
{
[array removeObjectsInArray:[deleteDic allKeys]];
[array writeToFile:Path atomically:YES];
[self.mytableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:[deleteDic allValues]] withRowAnimation:UITableViewRowAnimationFade];
[deleteDic removeAllObjects];
[array release];
}
//编辑按钮
-(void)editbtnClick
{
if ([self.navigationItem.rightBarButtonItem.title isEqual: @"编辑"])
{
self.navigationItem.rightBarButtonItem.title = @"确定";
[self.mytableView setEditing:YES animated:YES];
}
else
{
self.navigationItem.rightBarButtonItem.title = @"编辑";
[deleteDic removeAllObjects];
[self.mytableView setEditing:NO animated:YES];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.navigationItem.rightBarButtonItem.title isEqual: @"确定"])
{
[deleteDic setObject:indexPath forKey:[array objectAtIndex:indexPath.row]];
}
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (九) tableview的删除
- ios TableView那些事3(Swift 三) TableView 的删除操作
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度---tableview
- ios tableView那些事(二)给tableView添加数据
- ios tableView那些事 (五) 给tableview设置缩进级别
- 深度学习(二十八)基于多尺度深度网络的单幅图像深度估计-NIPS 2014
- iOS之横竖屏小结
- RHCE 学习笔记(18) 计划任务 at和 crontab
- C++面试题一
- pagingandsortingrepository接口实现分页查询
- ios tableView那些事 (九) tableview的删除
- R语言source()文件中文字符出现warning解决方法
- 2016蓝桥杯假期任务之《分糖果》
- 图像处理(一)图像变形(1)矩形全景图像还原-Siggraph 2014
- 2个更新UI的方法--activity.runOnUiThread及handler.post
- Android APP分享功能实现
- 求一个生成四位随机数的PHP代码
- UVA 1597 Search the Web
- MFC 基本操作 --修改对话框、静态文本背景颜色