尝试在Swift解除ViewController之后使用self.presentingViewController!.presentViewController时出错

时间:2015-05-21 19:56:02

标签: ios xcode swift

我总是遇到这样的错误

fatal error: unexpectedly found nil while unwrapping an Optional value

使用后

self.presentingViewController!.presentViewController 

内部完成

dismissViewControllerAnimated function  

这是我的代码。

// BeatBiddingModalViewController

self.dismissViewControllerAnimated(true, completion: { () -> Void in

        let navigation: UINavigationController = self.storyboard?.instantiateViewControllerWithIdentifier("dealInSideView") as! UINavigationController            
        let vc1: DealInsideViewController = navigation.topViewController as! DealInsideViewController

        vc1.dealId = self.dealId

        self.presentingViewController!.presentViewController(navigation, animated: true, completion: {})
        //fatal error: unexpectedly found nil while unwrapping an Optional value

    })

我该如何解决这个问题? 谢谢!

// appDelegate.swift

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    let navigationController = storyboard.instantiateViewControllerWithIdentifier("beatingDealView") as! UINavigationController
    let bealBiddingVc: BeatBiddingModalViewController = navigationController.topViewController as! BeatBiddingModalViewController

    bealBiddingVc.dealId = tempDealId
    bealBiddingVc.beatBiddingText = tempDealText
    bealBiddingVc.dealName = tempDealName
    self.window?.rootViewController?.presentViewController(navigationController, animated: true, completion: {})
}

**添加一些细节 该视图由appDelegate.swift呈现,而不仅仅是普通视图。

我的应用程序概念是从服务器接收Remote然后presentView以供用户采取某些操作。其中一个就是关闭这个模态presentView,然后通过通知给出另一个值。

0 个答案:

没有答案