tableviewcell添加多个按钮删除事件
2016-02-15 11:30
281 查看
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle ==
UITableViewCellEditingStyleDelete) {
[_dataArray
removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray
arrayWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationNone];
}
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath
{
//
添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"Delete"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){
[_dataArray
removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}];
//
删除一个置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"Top"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){
NSLog(@"The action to top");
}];
topRowAction.backgroundColor = [UIColor
blueColor];
//
添加一个更多按钮
UITableViewRowAction *moreRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"More"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){
NSLog(@"The action to more");
}];
moreRowAction.backgroundEffect = [UIBlurEffect
effectWithStyle:UIBlurEffectStyleDark];
//
将设置好的按钮放到数组中返回
return @[deleteRowAction, topRowAction, moreRowAction];
}
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle ==
UITableViewCellEditingStyleDelete) {
[_dataArray
removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray
arrayWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationNone];
}
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath
{
//
添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"Delete"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){
[_dataArray
removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}];
//
删除一个置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"Top"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){
NSLog(@"The action to top");
}];
topRowAction.backgroundColor = [UIColor
blueColor];
//
添加一个更多按钮
UITableViewRowAction *moreRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"More"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){
NSLog(@"The action to more");
}];
moreRowAction.backgroundEffect = [UIBlurEffect
effectWithStyle:UIBlurEffectStyleDark];
//
将设置好的按钮放到数组中返回
return @[deleteRowAction, topRowAction, moreRowAction];
}
相关文章推荐
- 『HTML5实现人工智能』小游戏《井字棋》发布,据说IQ上200才能赢【算法&代码讲解+资源打包下载】
- Linux系统如何查看版本信息
- java中的缓存技术该如何实现
- sql查询字段值的换行及回车符
- PHP导入导出excel表格图片的代码和方法大全
- mysql表名忽略大小写 未生效
- crf模型分词算法
- 传智播客168期JavaEE就业班(第七天 Java基础加强)
- linux下yum更新出现HTTP Error 404 NOT FOUND错误的办法
- C# WINFORM ListView用法详解(转)
- linux学习笔记十二:yum常用命令
- stm32资源网址
- WEB项目优化技巧(必会)
- jQuery命名空间无冲突
- iOS开发问题总结(持续更新...)
- Moving Tables
- android中activity相关任务栈(1)
- xslt/xpath对不存在属性的判断问题
- HTML5离线Web应用实战:五步创建成功
- JavaScript中的执行环境