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.
If you have an instance of a view controller, you can ask it:
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).
[view superview] to see whether the view has a superview.
[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.
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
Tag all the views you are interested in, for ex. tag on certain views of interest; "ImportantView1", "ImportantView2", ...
You need a (parent) view to make the above API call
The call will query the (parent) view and all subviews.
Filter the views by your custom tag name. (if tag starts with "ImportantView")