I have two view controllers: MyParentViewController
and MyChildViewController
.
The application starts with MyParent
. I push the MyChild
controller to the top of the navigation stack, so that the chain is like so:
MyParent
> MyChild
I log the object ID of MyChild
with NSLog(@"%p", self)
:
2009-11-20 05:08:29.305 MyApp[2213:207] MyChildViewController instance: 0x36afc20
When I press the back button from MyChild
this pops MyChild
off the stack and returns me to MyParent
.
When I rotate the iPhone while viewing MyParent
, my application crashes with the following error message:
2009-11-20 05:08:37.671 MyApp[2213:207] *** -[MyChildViewController _existingView]: message sent to deallocated instance 0x36afc20
I have no _existingView
method or instance variable in MyChildViewController
.
If I pop MyChild
off the stack, I think the navigation controller will release it, and I presume that it would be set to nil
, and that any messages sent to it would be ignored. Though that s not happening here, obviously.
Does anyone have any ideas why my application crashes on rotation?
Is there a way to find out what is sending the _existingView
message to MyChild
?
EDIT
Here s the code for pushing MyChild
on the stack:
MyChildViewController *_myChildViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];
_myChildViewController.managedObjectContext = self.managedObjectContext;
_myChildViewController.title = [_xyz name];
[self.navigationController pushViewController:_myChildViewController animated:YES];
UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"MyChildViewBackBarButtonItemTitle", @"") style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = _backButton;
[_backButton release];
[_myChildViewController release];
EDIT 2
I think I may have solved this. I have an UISearchDisplayController
added to the view controller nib via Interface Builder.
Originally, I set this to nil
when the MyChild
controller is sent -viewDidUnload
, thinking it is usually enough to set IBOutlet
instances to nil in this method. But this doesn t appear to be enough for my search display controller. When I release this in -dealloc
I don t get the crash. Is this a bug, I wonder, or expected behavior?