自定义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];
}
效果图