【iOS开发】添加系统自带的tableView左滑按钮

来源:互联网 发布:js在当前页面弹出窗口 编辑:程序博客网 时间:2024/05/16 02:04

自定义cell左滑出现几个按钮的需求。

采用iOS系统自带的方法来实现。

具体代理方法

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath;

完整代码如下

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"     删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {        // 具体逻辑代码    }];    deleteAction.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon_boxDelete_normal"]];    UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"     编辑" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {    }];    editAction.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon_boxEdit_normal"]];    return @[editAction, deleteAction];}

效果图

这里写图片描述

0 0
原创粉丝点击