如何实现列表滑动删除按钮

2025-05-01 18:31:16
推荐回答(2个)
回答1:

希望对你有帮助

效果这样:

代码:

手机侧滑事件


列表信息

  • 这是第一行,想删除请向左滑动

    删除

  • 这是第二行,想删除请向左滑动

    删除

回答2:

//Overridetosupporteditingthetableview.左滑删除functableView(tableView:UITableView,commitEditingStyleeditingStyle:UITableViewCellEditingStyle,forRowAtIndexPathindexPath:NSIndexPath){print("deletetableviewcell")ifeditingStyle==.Delete{//获取数组中要删除的数据letthis_password=self.todos[indexPath.row]this_password.delete{(result)inif(result.isSuccess){//根据result.isSuccess可以判断是否删除成功self.todos.removeAtIndex(indexPath.row)//删除对应的celltableView.deleteRowsAtIndexPaths([indexPath],withRowAnimation:.Fade)