У меня есть два контроллера представления, A и B.
A имеет табличное представление.
A обернуто в контроллер навигации, который позволяет ему выдвигать к B. B есть обработчик, которыйзвонки tableView.reloadData()
.Однако метод cellForRowAt
не вызывается в A до тех пор, пока не появится B, и A снова не станет видимым.
Существует ли формальная документация, в которой говорится, что cellForRowAt вызывается только тогда, когда VC является верхним контроллером представления?Это желаемый результат, и я хочу убедиться, что это произойдет.
-- denotes action
// denotes current VC
console denotes print message
//AVC:
--push to BVC
//BVC:
--press handler Button
console: "handling"
console: "nil"
console: "numberOfRowsInSection"
--press back navigation
console: "Disappearing"
//AVC:
console: "CellForROwAt"
Список файлов для воспроизведения
https://gist.github.com/MochaTheCoder/628af8950f39e5fc0896cc12d77c6fb2
- код -
class AViewController: UIViewController {
@objc private func pushBVC() {
let bVC = BViewController()
bVC.handler = {
print("handling")
print(self.view.window)
self.tableView.reloadData()
}
navigationController?.pushViewController(bVC, animated: true)
}
}
extension AViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("numberOfRowsInSection")
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("CellForROwAt")
return UITableViewCell()
}
}
----
class BViewController: UIViewController {
var handler: (() -> Void) = {}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("Disappearing")
}
@objc private func doHandler() {
handler()
}
}