问题
i have a scrollview loaded into my mainview (with pagecontrol). What i want to do is to have the scrollview use the "Touchesbegan" method to look for double taps and then have it push a new viewcontroller onto the navstack. The second goal seems impossible.
I have the seperated scrollviewcontroller call a method in the mainviewcontroller. That method should push a new viewcontroller onto the stack. It doesnt, but when i call this method from within the mainviewcontrollerclass it does work?!
in the scrollviewcontroller class:
MainViewController *mvcC = [[MainViewController alloc] init];
[mvcC loadMapView];
[mvcC release];
in the mainviewcontroller class:
-(void) loadMapView {
[[self navigationController] pushViewController:mapViewController animated:YES];
NSLog(@"loadMapView method is called!");
}
Thanks!
回答1:
You're allocating a new MainViewController
and sending your -loadMapView
message to that, rather than any existing MainViewController
in the navigation stack. Hence, [self navigationController]
in that method is nil and the -pushViewController:animated:
method is a no-op.
来源:https://stackoverflow.com/questions/6700800/push-viewcontroller-from-within-other-viewcontrollers-that-are-not-on-top-of-nav