gpt4 book ai didi

swift - 未调用 editActionsForRowAtIndexPath,目前同时提交 editingStyle 和 canEditRowAt

转载 作者:可可西里 更新时间:2023-11-01 00:58:14 25 4
gpt4 key购买 nike

我正在尝试向我的表格 View 行添加第二个滑动按钮,但是当我滑动一行时 editActionsForRowAtIndexPath 没有被调用。尽管我的类(class)同时声明了这两者

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {

return true
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

}

这两个在我滑动时都会被调用,因为我还有一个常规的删除按钮。

我的editActionsForRowAtIndexPath函数是这样写的:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewRowAction? {

print("triggered!")

let more = UITableViewRowAction(style: .default, title: "More") { action, index in
print("more button tapped")
}
more.backgroundColor = UIColor.blue

return more
}

提前致谢!

最佳答案

您没有为这个特定方法使用更新的 Swift 3 API。委托(delegate)方法应该写成:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
print("triggered!")

let more = UITableViewRowAction(style: .default, title: "More") { action, index in
print("more button tapped")
}
more.backgroundColor = UIColor.blue

return [more]
}

关于swift - 未调用 editActionsForRowAtIndexPath,目前同时提交 editingStyle 和 canEditRowAt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40121852/

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