在 Swift 中。我如何添加滑动以删除单元格(仍然显示删除的颜色和标签)但是当滑动结束时它会执行删除操作。我在其他地方看到了同样的问题,但这是针对 objective-c 的。我不确定 swift 是否对此有任何新的实现。任何帮助都会很棒。
谢谢
最佳答案
除了基本的 UITableView
实现之外,您还可以使用这两种方法:
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
objects.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
关于swift - 滑动即可删除单元格,而无需按删除按钮 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39177872/