【问题标题】:Changing the UITableViewCell swipe action title更改 UITableViewCell 滑动动作标题
【发布时间】:2016-02-04 18:20:49
【问题描述】:

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

我无法在处理函数中更改标题。另外,“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

}

【问题讨论】:

    标签: ios swift uitableview cocoa-touch uitableviewrowaction


    【解决方案1】:

    当您想要显示激活和停用时,您必须为每个索引路径手动管理单元格的状态。 保存单个 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]
    
    }
    

    【讨论】:

    • 是的,这是完美的,谢谢老兄。我早该想到的!!
    猜你喜欢
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多