I have a tab bar application, with many views. Is there a way to know if a particular UIViewController
is currently visible from within the UIViewController
? (looking for a property)
Ios – How to tell if UIViewController’s view is visible
iosuiviewuiviewcontrolleruiwindow
Related Topic
- Ios – How to make a UITextField move up when the keyboard is present – on starting to edit
- Ios – Passing data between view controllers
- Ios – UIDevice uniqueIdentifier deprecated – What to do now
- Ios – How to animate constraint changes
- Ios – Status bar and navigation bar appear over the view’s bounds in iOS 7
- Ios – How to use Auto Layout to move other views when a view is hidden
- Asp – HttpHandlers with ASP.NET MVC
Best Answer
The view's window property is non-nil if a view is currently visible, so check the main view in the view controller:
Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded. I've added the call to isViewLoaded to avoid this problem.
Since iOS9 it has became easier:
Or if you have a UINavigationController managing the view controllers, you could check its visibleViewController property instead.