【问题标题】:Change the title of UITableViewRowAction swift 3更改 UITableViewRowAction swift 3 的标题
【发布时间】:2017-08-08 13:11:56
【问题描述】:

我正在尝试更改 UITableViewRowAction 的标题,每次用户按下它就像完成/不完整一样,我编写的代码放置了复选标记但没有更改标题,因此无法删除复选标记:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let completeAction = UITableViewRowAction(style: .normal, title: "Complete", handler: { (action, indexPath) in
        if action.title == "Complete"{
            action.title = "Incomplete"
            cell?.accessoryType = UITableViewCellAccessoryType.checkmark
        }
        else{
            cell?.accessoryType = UITableViewCellAccessoryType.none
            action.title = "Complete"
        }
        tableView.setEditing(false, animated: true)
    })
    completeAction.backgroundColor = .blue
    return [completeAction]
}

有什么建议吗?

【问题讨论】:

    标签: swift3 uitableviewrowaction


    【解决方案1】:

    我就是这样解决的:

    var complete:Bool = false
    {
        didSet{
            if complete {
                comp = "Incomplete"
            }
            else{
                comp = "Complete"
            }
        }
    }
    var comp:String = "Complete"
    
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let cell = tableView.cellForRow(at: indexPath)
        let completeAction = UITableViewRowAction(style: .normal, title: "\(comp)", handler: { (action, indexPath) in
            if action.title == "Complete"{
                self.complete = true
                cell?.accessoryType = UITableViewCellAccessoryType.checkmark
            }
            else{
                self.complete = false
                cell?.accessoryType = UITableViewCellAccessoryType.none
            }
            tableView.setEditing(false, animated: true)
        })
        completeAction.backgroundColor = .blue
        return [completeAction]
    }
    

    【讨论】:

      猜你喜欢
      • 2016-04-23
      • 1970-01-01
      • 2015-01-09
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多