【发布时间】:2016-09-12 07:11:40
【问题描述】:
我有一个UITableView,我用UITableViewDelegate 和UITableViewDataSource 在控制器中管理它。在此表中,我有一个自定义单元格,问题是函数 editActionsForRowAtIndexPath 仅在某些时候被调用(也许当我以特定方式滑动时,我不知道),我的代码如下:
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let doneAction: UITableViewRowAction
//let highlightAction: UITableViewRowAction
if(self.compiti[indexPath.row].completato){
doneAction = UITableViewRowAction(style: .Normal, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
let compito = self.compiti[indexPath.row]
self.db.contrassegnaCompito(compito)
UITableViewRowAction
}
doneAction.backgroundColor = UIColor.redColor()
}else{
doneAction = UITableViewRowAction(style: .Normal, title: "Fatto") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
let compito = self.compiti[indexPath.row]
self.db.contrassegnaCompito(compito)
}
doneAction.backgroundColor = UIColor(red: 67/255, green: 160/255, blue: 71/255, alpha: 0.7)
}
return [doneAction]
}
【问题讨论】:
-
你是什么意思,也许当我以特定方式滑动时,我不知道?
-
你的tableView在scrollView里面吗?
-
@KumarKL 有时它可以工作......但我不知道为什么。如果我尝试 10 次 swypes 1 会起作用
-
@SamM 不,不是
-
你在真机上试过吗?问题仍然存在?
标签: swift uitableview uitableviewrowaction