For example we have three UIViewControllers: A, B, C.
We pushing B from A.
In B we calling some API:
func getProduct(productNumber: String) {
someService.rxGetProduct(productNumber: productNumber)
.asObservable()
.trackActivity(loading)
.subscribe(onNext: { [weak self] product in
guard let `self` = self else { return }
let cViewModel: CViewModel = .init()
let cViewController: CViewController = .init(viewModel: cViewModel)
self.navigationController?.pushViewController(cViewController, animated: true)
}, onError: { [weak self] error in
// error handling
}).disposed(by: disposeBag)
}
- In method above, we are getting some product model and pushing C view controller in closure.
The problem is, when we are popping back from C view controller to B view controller – C view controller is not deinitializing. C view controller is deinitializing when we are popping back from B view controller to A view controller.
What I am doing wrong?