check if the view is loaded at run time

Go To


Is there any way that I could see a view is loaded without checking the source code of that view controller (e.g., viewDidLoad, viewWillAppear, etc.)

or how can I check at the run time / dynamically if any view is loaded to grab the subviews.

2012-04-03 23:35
by ramo
e.g., I want to wait until my view is loaded and then get all subviews for that view and start doing test on them using something like KIF steps and scenarios by having those UIViews' properties and info. I want to wait til the view is loaded but then how can i get the UIViews' properties, because I dont want just use accessibility label - ramo 2012-04-03 23:59
by loaded I mean when we can get all the subviews of the view. I need to have this information grabbed from another lets say library file and not in the project source code - ramo 2012-04-04 00:01


If you have an instance of a view controller, you can ask it:

2012-04-04 00:03
by danh
then where should I check this and check isViewLoaded. So firt the applicationDidFinishLaunching is called and then the viewdidload of the first view is called. where can I check isViewLoade - ramo 2012-04-04 00:35


I'm not entirely clear on what you mean by "loaded." Depending on your definition of "loaded" you could:

  • Check if the view is nil (the broadest definition of loaded, though this will depend on someone nilling out the view when it is deallocated, lest you get an EXC_BAD_ACCESS).

  • Check [view superview] to see whether the view has a superview.

  • Check [view window] to see whether a view is part of a window (a prerequisite for being "on screen")

  • Assuming there is a corresponding UIViewController, query the controller's isViewLoaded property to see whether it has loaded a view into memory. This particularly helps with view life cycle issues.

There are probably other interpretations of "loaded" and other things you can check, but these are the first things off the top of my head.

2012-04-03 23:44
by Conrad Shultz


Not quite sure either about your use case, but this might help if you just want to query the view hierarchy.

- (UIView *)viewWithTag:(NSInteger)tag
  1. Tag all the views you are interested in, for ex. tag on certain views of interest; "ImportantView1", "ImportantView2", ...

  2. You need a (parent) view to make the above API call

  3. The call will query the (parent) view and all subviews.

  4. Filter the views by your custom tag name. (if tag starts with "ImportantView")

2012-04-03 23:52
by RyBolt