Skip to content

Instantly share code, notes, and snippets.

@Azuritul
Created August 31, 2011 08:54
Show Gist options
  • Save Azuritul/1183108 to your computer and use it in GitHub Desktop.
Save Azuritul/1183108 to your computer and use it in GitHub Desktop.
Check if a view controller is visible
/*
* Check http://stackoverflow.com/questions/2777438/how-to-tell-if-uiviewcontrollers-view-is-visible
* to see the discussions.
* If the container is a UINavigationController,
* we can use the visibleViewController property
* to check the visibility.
*/
navigationController visibleViewController == self
/* Or, we can add a category to UIViewController
* to check it.
*/
@interface UIViewController (CategoryName)
-(BOOL) isVisible;
@end
@implementation UIViewController (CategoryName)
-(BOOL) isVisible {
return [self isViewLoaded] && self.view.window;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment