从 AppDelegate.swift 中的 didReceiveLocalNotification 推送 ViewController

Pushing ViewController from didReceiveLocalNotification in AppDelegate.swift

当用户按下 Notification

时,我无法从 AppDelegate 推送 ViewController

下面是我的代码,但是由于 navigationController 为 nil 而导致此代码崩溃

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {

    var rootViewController = self.window!.rootViewController;

    let customDetailsViewController = CustomDetailsViewController();

    rootViewController?.navigationController!.pushViewController(customDetailsViewController, animated: true);
}

有什么想法吗?谢谢!!

如果您的导航控制器为 nil,那么您的 rootViewController(故事板中带有箭头的那个)不在 NavigationController 中。你能post你的 Storyboard 相关部分的屏幕截图吗?

编辑:

当您使用 RESideController 时,您将有一个 RootViewController 未连接到情节提要中的任何内容。 RootViewController 符合``协议,你有一些代码,如:

@implementation FASRootViewController

- (void)awakeFromNib
{
    self.menuPreferredStatusBarStyle = UIStatusBarStyleLightContent;

    self.scaleContentView = NO;
    self.scaleMenuView = NO;
    self.panGestureEnabled = YES;

    self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"];
    self.rightMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"rightMenuViewController"];
    self.delegate = (id<RESideMenuDelegate>)self.rightMenuViewController;
}

对于 "launch" 您的视图控制器,您需要在 Storyboard 中添加标识符

另外,这个视图控制器应该是一个 UINavigationController(不是你的第一个 "content" 视图控制器)