首页 文章

如何从Appdelegate导航到另一个viewcontroller

提问于
浏览
1

在我的iPhone应用程序中,我使用的是Pushnotifications . 当我收到通知时,我想从当前的viewcontroller转移到另一个viewcontroller . 我在appdelegate本身写了 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex . 我正在使用基于View的应用程序,所以我想使用 presentModalViewController (我认为) . 我使用以下代码:

UIViewController *view = (UIViewController*)self.viewController.presentedViewController;
                [view presentModalViewController:self.anotherVC animated:NO];

但是得到了错误

2012-06-19 17:47:52.521 iPhoneApp[1450:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <HomeScreenVC: 0x1fb77cc0>.'

这里出了什么问题?任何的想法 .

Edit 我将详细说明问题:我有viewcontrollers VC1,VC2,VC3和VC4 . 我的rootviewcontroller是VC1 . 如果我在VC2或VC4时发出推送通知,当我点击通知提醒的确定按钮时,我想转到VC3 . 但是警报视图的委托方法在appdelegate.m中 .

我更新了我的代码

self.menuVC = [[MenuScreenVC alloc] initWithNibName:@"MenuScreenVC" bundle:nil];
        UIViewController *view = (UIViewController*)self.viewController.presentedViewController;
        [view presentModalViewController:self.menuVC animated:NO];

现在我可以导航到VC3,如果我在VC2,我不能,如果我在VC4 . 请帮忙

1 回答

  • 3

    而不是你使用的是做以下事情

    [self.window.rootViewController presentModalViewController:self.anotherVC animated:NO];
    

相关问题