开发者

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

开发者 https://www.devze.com 2023-03-20 05:33 出处:网络
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 viewcont

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 ont开发者_Python百科o 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消