check if the view is loaded at run time

15,311

Solution 1

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

viewController.isViewLoaded

Solution 2

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.

Share:
15,311

Related videos on Youtube

ramo
Author by

ramo

Updated on June 04, 2022

Comments

  • ramo
    ramo almost 2 years

    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.

  • ramo
    ramo about 12 years
    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 isViewLoaded