更改 UITableViewCell 滑动操作标题

Changing the UITableViewCell swipe action title

我有一个标题为 "Activate" 的行操作按钮。当我按下它时,我希望标题更改为 "Deactivate".

我无法在处理函数中更改标题。另外,"Activate"和"Deactivate"应该有不同的功能。

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {

    let account = accountTypes[indexPath.section].accounts[indexPath.row]

    let delete = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler: { (action, indexPath) -> Void in
        // action delete
    })

    let activation = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Activate", handler: { (action, indexPath) -> Void in
        // action activate
    })
    activation.backgroundColor = UIColor.lightGrayColor()

    let arrayofactions: Array = [delete, activation]
    return arrayofactions

}

当您想要显示激活和取消激活时,您必须为每个索引路径手动管理单元格的状态。 为个人 indexpath 保存数据(条件)并在 editActionsForRowAtIndexPath 方法中放入以下条件。

let arrayofactions
if(condition true) {
  let activation = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Activate", handler: { (action, indexPath) -> Void in
    // action activate
  })
   activation.backgroundColor = UIColor.lightGrayColor()
   arrayofactions: Array = [delete, activation]
}
else {
   let deactivation = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "De-Activate", handler: { (action, indexPath) -> Void in
    // action deactivate
  })
   deactivation.backgroundColor = UIColor.lightGrayColor()
   deactivation: Array = [delete, deactivation]

}