【发布时间】:2017-02-28 12:44:13
【问题描述】:
我正在尝试向我的表格视图行添加第二个滑动按钮,但是当我滑动一行时,editActionsForRowAtIndexPath 没有被调用。尽管我的班级都声明了
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
}
提前致谢!
【问题讨论】:
-
你的
tableView的delegate属性设置了吗? -
我遇到了同样的问题,@Aaron 的回答对我有用。我不小心从班级中删除了 tableView 的委托。
-
如果其他人因其他原因遇到此问题,请注意此委托调用是在用户实际滑动 tableView 行时进行的,而不是在调用 tableView reloadData 时进行。确保没有任何东西覆盖 tableView 以防止滑动发生。
标签: swift tableview ios10 tableviewcell