I have two view controllers, A and B.
A has a tableview.
A is wrapped in a nav controller which allows it to push to B. B has a handler which calls tableView.reloadData()
. However, the cellForRowAt
method is not called in A until B has popped and A is visible again.
Is there formal documentation that states "cellForRowAt" is called only when the VC is the topmost view controller? This IS the desired result, and I want to ensure this is suppose to happen.
-- 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"
Gist of files for reproducing
https://gist.github.com/MochaTheCoder/628af8950f39e5fc0896cc12d77c6fb2
-- Code --
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()
}
}