这是问题所在,当我使用 TableViewController 并在选定的单元格上添加行为时。该行为显示两次
我怎样才能避免这种情况?
// MARK: - Table Deleget
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
UIView.animate(withDuration: 0.2, animations: {
cell?.viewWithTag(100)?.isHidden = true
(cell?.viewWithTag(200) as! UILabel).textColor = UIColor.red
})
}
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
UIView.animate( withDuration: 0.3, animations: {
cell?.viewWithTag(100)?.isHidden = false
(cell?.viewWithTag(200) as! UILabel).textColor = UIColor(red: 0, green: 128/255, blue: 128/255, alpha: 1)
})
}
最佳答案
将动画从“cellForRow”方法移动到'willDisplayCell'方法。我认为它可以帮助您避免两次动画。
关于ios - 如何避免 Reusable Cell 的复制行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45878049/