在自己的功能中无法推动视图控制器

时间:2016-01-06 09:29:38

标签: ios swift uiviewcontroller segue

我创建了一个UIViewController,它有一个完成处理函数,因为它必须从数据库加载数据,segue的代码是:

func S0000 () {

    let V = self.storyboard!.instantiateViewControllerWithIdentifier("V0003") as! V0003

    V.Cv { (Con) -> Void in

        NSOperationQueue.mainQueue().addOperationWithBlock {
            self.showViewController(V, sender: self)
        }
    }
}

这会引发错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

我怎样才能让它发挥作用以及我做错了什么。

只是为了获取信息,我发现当我以这种方式运行时它可以工作,但是当推送到它时,ofcours没有完成加载它因为它在完成处理程序返回之前推送。

func S0000 () {

    let V = self.storyboard!.instantiateViewControllerWithIdentifier("V0003") as! V0003

self.showViewController(V, sender: self)

    V.Cv { (Con) -> Void in
        NSOperationQueue.mainQueue().addOperationWithBlock {    
        }   
    }   
}

1 个答案:

答案 0 :(得分:1)

试试这个

V.Cv { (Con) -> Void in

NSOperationQueue.mainQueue().addOperationWithBlock {
    let V = self.storyboard!.instantiateViewControllerWithIdentifier("V0003") as! V0003
    self.showViewController(V, sender: self)
    }
}