Swift UITableViewRowAction不工作
我有一个Swift UITableViewRowAction不工作,swift,uitableview,uitableviewrowaction,Swift,Uitableview,Uitableviewrowaction,我有一个UITableView,我用UITableViewDelegate和UITableViewDataSource在控制器中管理它。在这个表中,我有一个自定义单元格,问题是函数editActionsForRowAtIndexPath有时才被调用(可能当我以特定方式键入时,我不知道),我的代码如下: func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
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]
}
这段代码对我很有用,试着从这开始,你可能会发现问题何时出现
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
var doneAction :UITableViewRowAction!
doneAction = UITableViewRowAction(style: .Default, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
UITableViewRowAction
}
return [doneAction]
}
您还需要添加此方法实现,否则将无法滑动以显示操作
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
// it can be empty
}
你是什么意思,也许当我以一种特殊的方式打字时,我不知道?你的tableView在scrollView中吗?@KumarKL,有时它会工作。。。但我不知道为什么。如果我尝试10种类型,我会work@SamM不,不是,你没试过真正的设备吗?问题依然存在?仍然没有行动,我想在我的手机里可能还有其他东西在“捕捉”这个动作……这对我很有用。(基于我们需要使用的版本)