How to check if a specific UIViewController's view is currently visible? [duplicate]
After doing some research, I found this answer in a different question posted on here...This seems to be the best way...
The view's window property is non-nil if a view is currently visible, so check the main view in the view controller:
if (viewController.isViewLoaded && viewController.view.window){
// viewController is visible
}
Add this to your controllers, or to a subclass of UIViewController that you can then subclass further. Access it using a property or the variable:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
visible = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
visible = NO;
[super viewWillDisappear:animated];
}