如何从UITableViewRowAction更改特定单元格的字体颜色?

时间:2017-02-19 20:19:31

标签: swift uitableview

我使用UITAbleViewRowAction添加了一个自定义按钮,因此当用户向左滑动时,他/她会看到该按钮。当他/她按下该按钮时,如何让按钮更改该特定行的字体颜色?谢谢!

1 个答案:

答案 0 :(得分:0)

我假设您已实施tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?,那么您可以在行动中执行此操作:

let action = UITableViewRowAction(style: .normal, title: "Action") { (action, indexPath) in
    let cell = tableView.cellForRow(at: indexPath)
    cell?.textLabel?.textColor = .red
    tableView.setEditing(false, animated: true)
}
return [action]

如果你已经UITableViewCell进行了子类化,那么你必须要做

let cell = tableView.cellForRow(at: indexPath) as! MySubclassTableViewCell

并编辑班级内的适当标签。

或者,您可以将indexPath存储在闭包之外并重新加载tableView。

相关问题