gpt4 book ai didi

uitableview - Swift:如何使用“编辑”按钮删除并停用滑动以删除?

转载 作者:可可西里 更新时间:2023-10-31 23:56:34 25 4
gpt4 key购买 nike

我在导航栏中添加了一个带有 IBAction 的编辑按钮:

@IBOutlet weak var editButton: UIBarButtonItem!

@IBAction func doEdit(sender: AnyObject) {

if (self.tableView.editing) {
editButton.title = "Edit"
self.tableView.setEditing(false, animated: true)
} else {
editButton.title = "Done"
self.tableView.setEditing(true, animated: true)
}
}

用于删除我拥有的单元格

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
arr.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}

不幸的是,这也会激活滑动删除。如何在不执行滑动删除的情况下删除单元格?

最佳答案

解决方案(来自 this answer ),翻译成 Swift:

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
if (self.tableView.editing) {
return UITableViewCellEditingStyle.Delete;
}

return UITableViewCellEditingStyle.None;
}

关于uitableview - Swift:如何使用“编辑”按钮删除并停用滑动以删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29672666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com