更改UITableViewCell滑动动作标题 [英] Changing the UITableViewCell swipe action title
本文介绍了更改UITableViewCell滑动动作标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个标题为激活"的行动作按钮.当我按下它时,我希望标题更改为停用".
I have a row action button titled "Activate". When I press it, I want the title to change to "Deactivate".
我无法在处理程序函数中更改标题.另外,激活"和停用"应具有不同的功能.
I was unable to change the title in the handler function. Also, "Activate" and "Deactivate" should have different functions.
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 方法中.
You have to manage your cell's state manually for each indexpath when you want to show activate and de-activate. Save data(condition) for individual indexpath and put below condition in your editActionsForRowAtIndexPath method.
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]
}
这篇关于更改UITableViewCell滑动动作标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文