更改UITableViewCell滑动操作标题

我有一个名为“激活”的行操作button。 当我按下它时,我希望标题变成“停用”。

我无法改变处理函数的标题。 另外,“激活”和“停用”应具有不同的function。

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 

}

当你想显示激活和取消激活时,你必须为每个索引path手动pipe理你的单元格的状态。 保存单个索引path的数据(条件),并将下面的条件放在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] }