【问题标题】:UITableViewRowAction not workingUITableViewRowAction 不起作用
【发布时间】:2016-09-12 07:11:40
【问题描述】:

我有一个UITableView,我用UITableViewDelegateUITableViewDataSource 在控制器中管理它。在此表中,我有一个自定义单元格,问题是函数 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


【解决方案1】:

您还需要添加此方法实现,否则您将无法滑动显示操作

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    // it can be empty
}

【讨论】:

  • 它对我有用。 (基于我们需要使用的版本)
【解决方案2】:

这段代码对我有用,尝试从这里开始,你可能会发现问题发生的时间

 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]
}

【讨论】:

  • 仍然没有动作,我认为我的牢房中可能还有其他东西正在“捕获”动作......
猜你喜欢
  • 2020-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多