Reputation: 57
In every UIViewController I got the deinit function with a simple print statement that tells me when that specific UIViewController is deleted from memory.
deinit {
print("VIEWCONTROLLER DELETED FROM MEMORY")
}
However, all UIViewController which are part of the UITabBarController will never call deinit and I never see the print statement in the console.
And in addition to that:
Code which is inside...
NotificationCenter.default.addObserver(forName: UIApplication.didChangeStatusBarOrientationNotification, object: nil, queue: OperationQueue.main) { (notification) in
print("Device rotated")
}
... will be called on the other tabs also. So when the device switches from Landscape to Portrait all code inside the closure above will be executed even when I´m not in the UIViewcontroller where that specific piece of code is in...strange!
Why is that?
Upvotes: 1
Views: 76
Reputation: 754
Well, UITabBarController is working perfectly as expected. Might be you have gone through the wrong way. If you want to observe the notification you can observe it in the class of UITabBarController instead of the ViewController inside of UITabBarController. For more info you can go through the apple document of the UITabBarController.
Upvotes: 1