popToRootViewController is crashing when more than two view controllers are being popped
I have a strange situation with calling popToRootViewController on my navigation controller. If there are only one or two view controllers on top of the root to pop, it works just fine. If there are more than two view controllers on top of the root on the stack, it crashes. I've looked around all of the popToRootViewController complaints on this site and others and have tried setting animated to NO. This does not help. I've also seen some people citing an issue with iOS 3.0 with popToRootViewController on very old posts, but I am developing on iOS 4.0.
To be more explicit, if my stack looks like this: RootVC --> VC1 --> VC2. And then I do
[self.navigationController popToRootViewControllerAnimated:NO];
from VC2, it pops to the root as exp开发者_开发知识库ected. However, if my stack looks like this: RootVC --> VC1 --> VC2 --> VC3 and then do the same exact thing from VC3, it crashes. Any clues as to what could be the problem? I apologize if this is a really dumb question. I'm a newcomer to iPhone developement.
I am using the following code for pushing each of my views onto the stack:
-(void)pushViewNamed:(NSString *)viewname
{
iOvulate_3AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSString *viewControllerName=viewname;
UIViewController *targetViewController=[[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil];
[self.navigationController pushViewController:targetViewController animated:YES];
if ( [appDelegate.pdbool intValue] == 0 )
{
[viewControllerName release];
[targetViewController release];
}
}
I put the conditional release there because it solved a different problem I was having where IBActions on any view beyond the third view on the stack weren't working--as in touching inside a button was causing a message to be sent to a nil object that was supposed to be the view controller (or something like that?) and causing EXC_BAD_ACCESS error. Could this "fix" be causing the memory management problems you speak of?
Why don't you try looking at each of the View Controllers on your nav stack? Use:
[self.navigationController.viewControllers objectAtIndex:index];
To see the view controller at the corresponding index
. If they appear all fine, then it must be something else in your code that is causing the crash. Hope that helps!
精彩评论