[英]Can't push view controller while in its own function
I made A UIViewController which has a Completion handler function on it because it has to load data from a database, the code for the segue there is : 我做了一个UIViewController,上面有一个Completion处理函数,因为它必须从数据库中加载数据,那里的代码是:
func S0000 () {
let V = self.storyboard!.instantiateViewControllerWithIdentifier("V0003") as! V0003
V.Cv { (Con) -> Void in
NSOperationQueue.mainQueue().addOperationWithBlock {
self.showViewController(V, sender: self)
}
}
}
This throws the error : 这引发了错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
How could I make it work and what am I doing wrong. 我如何使它正常工作以及我在做什么错。
And just for information I found out that when I run it this way It works but ofcours is not finished loading when pushing to It becuase It pushes before the completion handler returns. 仅作为参考,我发现以这种方式运行它可以正常工作,但是推入It时ofcours尚未完成加载,因为它在完成处理程序返回之前就进行了推入。
func S0000 () {
let V = self.storyboard!.instantiateViewControllerWithIdentifier("V0003") as! V0003
self.showViewController(V, sender: self)
V.Cv { (Con) -> Void in
NSOperationQueue.mainQueue().addOperationWithBlock {
}
}
}
Try this 尝试这个
V.Cv { (Con) -> Void in
NSOperationQueue.mainQueue().addOperationWithBlock {
let V = self.storyboard!.instantiateViewControllerWithIdentifier("V0003") as! V0003
self.showViewController(V, sender: self)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.