从不在 Navstack 之上的其他 ViewController 中推送 ViewController? [英] Push Viewcontroller from within other ViewControllers that are not on top of Navstack?
问题描述
我有一个滚动视图加载到我的主视图中(带有页面控制).我想要做的是让滚动视图使用Touchesbegan"方法来寻找双击,然后让它将一个新的视图控制器推送到导航堆栈上.第二个目标似乎是不可能的.
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.
我有单独的滚动视图控制器在主视图控制器中调用一个方法.该方法应该将一个新的视图控制器推送到堆栈上.它没有,但是当我从 mainviewcontrollerclass 中调用此方法时,它确实有效?!
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];
在主视图控制器类中:
-(void) loadMapView {
[[self navigationController] pushViewController:mapViewController animated:YES];
NSLog(@"loadMapView method is called!");
}
谢谢!
推荐答案
您正在分配一个新的 MainViewController
并向其发送 -loadMapView
消息,而不是任何导航堆栈中现有的 MainViewController
.因此,该方法中的 [self navigationController]
是 nil 并且 -pushViewController:animated:
方法是空操作.
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.
这篇关于从不在 Navstack 之上的其他 ViewController 中推送 ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!