Push Viewcontroller from within other ViewControllers that are not on top of Navstack?

a 夏天 提交于 2019-12-08 04:34:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!