我有一个用UITableViewDelegate和UITableViewDataSource在控制器中管理的UITableView。在这个表中,我有一个自定义的单元格,问题是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]
}发布于 2016-11-22 18:53:12
您还需要添加此方法实现,否则将无法滑动来显示操作
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
// it can be empty
}发布于 2016-09-12 21:22:07
它适用于我的这段代码,试着从这里开始,你可能会发现什么时候出现问题
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]
}https://stackoverflow.com/questions/39445043
复制相似问题