简体   繁体   English

从AppDelegate.swift中的didReceiveLocalNotification推送ViewController

[英]Pushing ViewController from didReceiveLocalNotification in AppDelegate.swift

I am having problem in pushing ViewController from AppDelegate when user pressed the Notification 我在按下通知时从AppDelegate推送ViewController时遇到问题

Below is my code, but this code Crashes because the navigationController is nil 下面是我的代码,但是由于navigationController为nil,此代码崩溃

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

    var rootViewController = self.window!.rootViewController;

    let customDetailsViewController = CustomDetailsViewController();

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

Any idea? 任何想法? Thank you!! 谢谢!!

If your navigation controller is nil, then your rootViewController (the one with the arrow in your Storyboard) is not inside a NavigationController. 如果导航控制器为nil,则rootViewController(情节提要中带有箭头的那个)不在NavigationController内。 Can you post a screenshot of the relevant part of your Storyboard? 您可以发布情节提要的相关部分的屏幕截图吗?

EDIT : 编辑

As you are using RESideController , you'll have a RootViewController not connected to anything in your Storyboard. 当您使用RESideController时 ,您将有一个RootViewController未连接到Storyboard中的任何东西。 That RootViewController conforms to ``protocol and you have some code like: RootViewController符合``protocol,您有一些类似的代码:

@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;
}

To "launch" your View controllers your need to add a identifier in the Storyboard 要“启动” View控制器,需要在情节提要中添加标识符

在情节提要中添加一个标识符

Also, this View Controller should be a UINavigationController (not your first "content" view controller) 此外,此视图控制器应为UINavigationController(而不是您的第一个“内容”视图控制器)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM