Swift UITable查看willDisplay和DiEndDisplay的顺序
我在两个委托方法中遇到了非常奇怪的行为Swift UITable查看willDisplay和DiEndDisplay的顺序,swift,uitableview,Swift,Uitableview,我在两个委托方法中遇到了非常奇怪的行为 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { print("will display \(indexPath.section) - \(indexPath.row)") addInputRules(tableView, cell, indexPath)
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
print("will display \(indexPath.section) - \(indexPath.row)")
addInputRules(tableView, cell, indexPath)
}
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
print("did end display \(indexPath.section) - \(indexPath.row)")
removeInputRules(tableView, cell, indexPath)
}
我在滚动时向表视图单元格添加和删除输入验证规则。
它工作得很好。但当我用
tableView.reloadSections(IndexSet([indexPath.section]), with: .automatic)
调用了willDisplay和DiEndDisplaying委托方法,但顺序不正确
有willDisplay和之后的dienddisplay
will display 0 - 0
will display 0 - 1
will display 0 - 2
will display 0 - 3
will display 0 - 4
will display 0 - 5
did end display 0 - 0
did end display 0 - 1
did end display 0 - 2
did end display 0 - 3
did end display 0 - 4
did end display 0 - 5
did end display 0 - 0
did end display 0 - 1
did end display 0 - 2
did end display 0 - 3
did end display 0 - 4
did end display 0 - 5
是什么导致我的验证规则被删除 Cocoa是事件驱动的。在
didendisplaying
中,您不必在意之前是否给出了相应的显示。只需对其进行编码。若单元格在表视图中出现或消失,则应调用它们,但此处它与屏幕上显示的内容不一致。我需要将代码替换为reloadData(),以获得正确的will display/end display。我正在注册/注销当前可见单元格中输入字段的验证规则,因此顺序很重要。您可以向Apple提交错误报告。但与此同时,我们必须接受现实。你不能说什么时候该叫什么。在某些情况下,调用viewwillbeen
,而不调用viewdidebeen
。这似乎是错误的,但这就是生活。这是相似的。正如我所说,你只需要围绕它编码。