iOS小明开发笔记(九) (tableViewCell侧滑显示多个按钮)
来源:互联网 发布:华科达软件下载 编辑:程序博客网 时间:2024/05/21 08:01
平常中所用的tableViewCell,左滑后,编辑状态只有一个删除按钮,现在很多APP上面都自定义实现了cell侧滑自定义编辑按钮,比如qq,微信侧滑后有“消息置顶”、“标记为未读”等。
话不多说, 代码如下:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了删除");
// 1. 更新数据
NSMutableArray *arrModel = self.dataSource[indexPath.section];
[arrModelremoveObjectAtIndex:indexPath.row];
// 2. 更新UI
[tableViewdeleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
// 删除一个置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"置顶"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了置顶");
// 1. 更新数据
[self.dataSourceexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:0];
// 2. 更新UI
NSIndexPath *firstIndexPath = [NSIndexPathindexPathForRow:0 inSection:indexPath.section];
[tableViewmoveRowAtIndexPath:indexPath toIndexPath:firstIndexPath];
}];
topRowAction.backgroundColor = [UIColorblueColor];
// 添加一个更多按钮
UITableViewRowAction *moreRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"更多"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了更多");
[tableViewreloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
}];
moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
// 将设置好的按钮放到数组中返回
return @[deleteRowAction, topRowAction, moreRowAction];
}
- iOS小明开发笔记(九) (tableViewCell侧滑显示多个按钮)
- iOS陆哥开发笔记(十二) (tableViewCell侧滑显示多个按钮)
- iOS tableviewcell滑动删除时显示多个按钮
- iOS开发-修改TableViewCell的Delete按钮
- tableView侧滑显示多个按钮(IOS 8.0)
- tableviewcell添加多个按钮删除事件
- ios tableViewCell滑动实现多按钮
- iOS---点击tableviewcell中的按钮
- 玩转tableViewCell 侧滑按钮UITableViewCellDeleteConfirmationView
- IOS开发-tableViewCell 的小demo,group分组。
- 1.IOS TableView滑动显示多个按钮
- IOS界面弹窗显示多个按钮
- iOS之tableView左划显示多个按钮
- UITableViewCell侧滑显示多个选项按钮
- iOS开发笔记--彩色小图标显示方法
- iOS开发笔记--彩色小图标显示方法
- iOS开发 自定义tableviewCell、自动变高、动态布局、删除按钮替换图片和文字
- iOS开发 -定制TableViewCell
- 程序员面试题精选100题(38)-输出1到最大的N位数[算法]
- va_start 和va_end应用
- 第2章 使用ListView显示信息列表
- sql server 2008 安装中遇到的问题之Sql Server服务远程过程调用失败解决
- 100. Same Tree
- iOS小明开发笔记(九) (tableViewCell侧滑显示多个按钮)
- 程序员面试题精选100题(39)-颠倒栈[数据结构]
- 使用Android Studio,新建library并发布到jCenter
- 使用CocoaPods管理依赖库
- iOS海哥开发笔记 (海哥原创,iOS 之mac终端命令大全介绍 )
- 程序员面试题精选100题(40)-扑克牌的顺子[算法]
- 工作中遇到的关于页面刷新跳转的问题
- 搜索栏有内容搜索商品,清空UITextField返回搜索历史
- 大麦购票