How to check if view is inViewHierarchy or not?

For example, if the view viewController is in viewHierarchy, and I just finished loading, I want to quickly update the material. If self.view does not appear in the hierarchy, I want to postpone the update.

I suppose I can just add a boolean to indicate this, and put it in viewWillAppear and viewWillDisappear.

I can also scan windows and see if there is a UIView in the view hierarchy or not.

Is there an easier way?

+4
source share
3 answers

In your view, the controller:

if (self.isViewLoaded && self.view.window != nil) { // view is in a view hierarchy and should be updated } 
+13
source

viewDidLoad will only be launched after the loading download has completed, I think. Therefore, I think you can add the necessary functions to viewDidLoad.

+1
source

To check if there is a view in the hierarchy, this is enough:

 // From a UIViewController sub-class if !self.isViewLoaded { // view is not in the view hierarchy } 
0
source

All Articles