IOS开发入门:实现UITableViewCell的左滑操作(编辑、删除等)
2017-05-20 11:48
501 查看
单个左滑按钮的实现
如果左滑后只需要一个按钮,只要在实现UITableViewDelegate的Controller中实现下面的委托方法:-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //处理删除的操作 }
默认的编辑模式是
UITableViewCellEditingStyleDelete。如果想改变作画按钮上的文字可以用:
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"更新"; }
想要改变按钮的背景颜色可以参照这篇文章
自定义多个左滑按钮
实现下面的委托方法,按钮的背景颜色和名称都可以自定义://多个自定义的按钮 - (nullable NSArray<UITableViewRowAction *> *) tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewRowAction *uploadAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Upload" handler:^(UITableViewRowAction *action,NSIndexPath *path) { NSLog(@"upload事件"); //需要实现的操作 }]; uploadAction.backgroundColor = [UIColor cyanColor]; UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action,NSIndexPath *path) { NSLog(@"delete事件"); //需要实现的操作 }]; NSArray *actionArray = [NSArray arrayWithObjects:deleteAction,uploadAction,nil]; return actionArray; }
相关文章推荐
- iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除
- ios开发之实现长按UITableViewCell弹出UIMenuController, 实现文字拷贝等操作
- iOS 开发-实现TableView的编辑功能以删除数据
- iOS开发系列 ---- UI (TableView的编辑和多项删除操作)
- iOS开发-UI控件:UITableViewCell划动删除的实现
- iOS开发_iphone 实现剪贴板操作_iphone 复制粘贴功能(转)
- ios开发之实现长按UITableViewCell弹出UIMenuController
- repeater控件实现 编辑 删除等 操作
- 如何在DataGrid控件中实现编辑、删除、分类以及分页操作
- ios开发之实现长按UITableViewCell弹出UIMenuController
- ASP.NET MVC3 快速入门-第九节 实现编辑、删除与明细信息视图
- DataGrid的使用:(一)、在DataGrid控件中实现基本的操作(编辑、删除、分页)
- 可视化webpart基础开发——利用事件接收器实现同步操作两个文档库(添加、删除、修改文档)
- DataGrid的使用:(一)在DataGrid控件中实现基本的操作(编辑、删除、分页)
- js实现批量删除,编辑操作
- 【IOS开发】IOS开发新手入门--简单计算器实现
- ios开发:UITableViewCell的操作
- DataGrid控件实现编辑、删除、分类以及分页操作
- DataGrid控件实现编辑、删除、分类以及分页操作
- 如何在DataGrid控件中实现编辑、删除、分类以及分页操作