ios - 如何避免 Reusable Cell 的复制行为

标签 ios swift uitableview

这是问题所在,当我使用 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)
    })

}

first one identical one

最佳答案

将动画从“cellForRow”方法移动到'willDisplayCell'方法。我认为它可以帮助您避免两次动画。

关于ios - 如何避免 Reusable Cell 的复制行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45878049/

相关文章:

ios - 允许点击通过 UITapGestureRecognizer 并到达下面的表格 View

ios - 如何在 iOS 中使用 whatsapp 共享或打开 pdf 文件?

ios - AFNetworking 请求返回 nil

ios - NSSearchPathForDirectoriesInDomains 在模拟器上工作但不在设备上工作

swift - Safari 应用程序扩展弹出窗口不调用 TableView 通知方法

ios - 在自定义单元格按钮操作中获取节号

iOS:从带有 M8 芯片的 iPhone 6 获取当前大气压力

iOS 用户角色最佳实践

ios - 用于 iOS 应用程序的绑定(bind)技术

ios - 如何将 TableView 动态单元格链接到特定的 View Controller ?