I have an iPhone view controller that's initialized with a XIB.
If a view controller's view is not visible when a memory warning comes through, it sets its view to nil (releasing it). But when an overlapping view is dismissed and the cleared-out view becomes visible again, Cocoa doesn't reload it from the XIB; it simply creates a blank one. This leaves a blank white screen, and a broken app.
The Apple doc for UIViewController's loadView method says, "If the view controller has an associated nib file, this method loads the view from the nib file. A view controller has an associated nib file if the nibName property returns a non-nil value." So I overrode loadView simply to check nibName after initializing the controller, and nibName is correct. So subsequent calls to loadView should be reloading from the XIB. I verified that loadView is called again after the memory warning.
UPDATE: With more testing and logging, I've determined that after the second viewDidLoad call, the view's IBOutlets are non-nil. Since I set them to nil in viewDidUnload, I conclude that the view was indeed reloaded from the XIB. So why is it showing up as an all-white screen?
Thanks for any insight.
Here's viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
_photoViewController = [[EGOSimplePhotoViewController alloc] initWithPhotoSource:_photoSource
scrollView:bigImageScrollView
enclosingView:photoSquare];
_photoViewController.delegate = self;
if(_progressHUD == nil)
{
if(self.navigationController.view != nil)
{
_progressHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
}
else
{
_progressHUD = [[MBProgressHUD alloc] initWithView:self.view];
}
}
// Add HUD to screen.
if(self.navigationController.view != nil)
{
[self.navigationController.view addSubview:_progressHUD];
}
else
{
[self.view addSubview:_progressHUD];
}
[_progressHUD release];
_progressHUD.labelText = @"Loading...";
[_progressHUD show:YES];
}
And viewDidUnload:
- (void)viewDidUnload
{
[_photoViewController release];
[super viewDidUnload];
}
viewDidUnload
? – CostiqueloadView
. Please show us the code inloadView
,viewDidLoad
andviewDidUnload
. – Costique[super viewDidUnload]
in yourviewDidUnload
? Did you overrideloadView
? The system should absolutely be sending youloadView
(and thenviewDidLoad
) if it has previously sent youviewDidUnload
. – rob mayoff