Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to determine that a UIViewController has been loaded, and has a valid view?

When the view property of a UIViewController is accessed, it first checks to see if it's got an existing view, and returns that. If not, it loads its nib or calls -loadView.

When a controller receives a -didReceiveMemoryWarning message, the default behavior is to remove that cached view (assuming it's not in use at the time).

If I override -didReceiveMemoryWarning, how can I determine whether the view has been cleared? My understanding is that the default implementation checks to see if self.view.superview == nil. If so, it clears the cached view. Of course, it first checks to see if there is a cached view, and if not, it does nothing. However, I, as a subclass, can't call self.view.superview, for if there isn't a view, it'll generate one.

So, how do I figure out if _view exists? (I can't just look at _view; I get linking errors when building for the device).

like image 613
Ben Gottlieb Avatar asked Dec 04 '08 05:12

Ben Gottlieb


1 Answers

Since iPhone OS 3.0, you can use the isViewLoaded method to see if a view is loaded.

like image 66
Zargony Avatar answered Nov 06 '22 10:11

Zargony