我使用 UITAbleViewRowAction 添加了一个自定义按钮,因此当用户在一行上向左滑动时,他/她会看到该按钮。当他/她按下该按钮时,如何让按钮更改该特定行的字体颜色?谢谢!
最佳答案
我假设您实现了 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
,那么您必须这样做
让 cell = tableView.cellForRow(at: indexPath) as! MySubclassTableViewCell
并在类中编辑适当的标签。
或者,您可以将indexPath存储在闭包之外并重新加载tableView。
关于swift - 如何从 UITableViewRowAction 更改特定单元格的字体颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42332399/