This is my first time asking a question in this site. as an amateur developer, I always found answers to my questions in this site, but I could not find one to my current problem.
In my iPad app I call a new UIViewController from the rootView:
DisplayTheMapViewController_iPad *root = [[DisplayTheMapViewController_iPad alloc] init];
displayTheMapViewController=root;
[[self navigationController] pushViewController:displayTheMapViewController animated:YES];
[root release];
When I go back from this view to the main view the application crashes (it takes a minute or so, and until then everything is normal, but it always happens), with an auto release pool error.
when I comment [root release] the app stays alive, but then I hav开发者_如何转开发e a different problem: On my second visit to the view (not the first!) when a call a method that puts a popover in the view, the app crashes and I get the following error:
'Popovers cannot be presented from a view which does not have a window.'
I must do something wrong. I thank you in advance for any advice.
This line is a bit puzzling:
displayTheMapViewController=root;
I'm guessing that displayTheMapViewController
is an instance variable? If so, you're assigning root to it, but you're not retaining root. When that controller is popped off the navigation stack, the navigation controller will release it, causing it to be deallocated because nothing else has retained it. displayTheMapViewController
will then point to an invalid object. Perhaps you meant to say:
self.displayTheMapViewController=root;
If the displayTheMapViewController
property is set to retain its contents, that'd prevent the dangling pointer problem above.
Check your DisplayTheMapViewController_iPad class top bottom that you forgot to release a allocated object.
You don't post enough code to fully diagnose the problem, but I would suggest checking the line: displayTheMapViewController = root;
. Since you are not retaining root
, displayTheMapViewController
will be left dangling after the view controller is removed from the navigation controller.
As to what happens when you do not release root and reenter the view, I suspect this is something related to the internals of DisplayTheMapViewController_iPad
once you have a second instance of it around.
精彩评论