UIContextualAction单元格侧滑按钮

  • (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {

    UIContextualAction *deleteAction = [UIContextualAction
    contextualActionWithStyle:UIContextualActionStyleDestructive
    title:@"删除"
    handler:^(UIContextualAction * _Nonnull action,
    __kindof UIView * _Nonnull sourceView,
    void (^ _Nonnull completionHandler)(BOOL))
    {
    [self.titles removeObjectAtIndex:indexPath.row];

      [self.tableView deleteRowsAtIndexPaths: [NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
      
      completionHandler(true);
    

    }];

    // 设置按钮图片
    [deleteAction setImage:[UIImage imageNamed:@"Star"]];

NSArray *actions = [[NSArray alloc] initWithObjects:deleteAction, nil];

return [UISwipeActionsConfiguration configurationWithActions:actions];

}

你可能感兴趣的:(UIContextualAction单元格侧滑按钮)