从AppDelegate.swift中的didReceiveLocalNotification推送ViewController

时间:2015-03-30 06:24:00

标签: ios xcode swift notifications

当用户按下通知

时,我在从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);
}

有什么想法吗?谢谢!!

1 个答案:

答案 0 :(得分:1)

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

修改

当您使用RESideController时,您的RootViewController将无法连接到Storyboard中的任何内容。 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;
}

To&#34; launch&#34;您的View控制器需要在故事板中添加标识符

add a identifier in the Storyboard

此外,此View Controller应该是UINavigationController(不是您的第一个&#34;内容&#34;视图控制器)