0

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

我无法更改处理程序函数中的标题。此外,“激活”和“停用”应该具有不同的功能。

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

}

4

1 回答 1

0

当您想要显示激活和停用时,您必须为每个索引路径手动管理单元的状态。保存单个索引路径的数据(条件)并将以下条件放在您的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]

}
于 2016-02-04T18:36:21.263 回答