我想通过storyboard中的init传递storyboard中的值。这段代码在 xib 中使用效果很好。但在 Storyboard中我的应用程序崩溃了。这是我的代码片段,请帮助任何帮助,我们将不胜感激。
在 FirstviewController 中
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
viewControllerd = storyboard.instantiateViewControllerWithIdentifier("a") as? SecondViewController
viewControllerd = SecondViewController.init(title: "helo")
addViewControllerAsChildViewController(viewControllerd!)
第二 View Controller
init(title : String)
{
a = title
super.init(nibName: "SecondViewController", bundle: nil)
}
required init(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)!
}
最佳答案
viewControllerd = SecondViewController.init(title: "helo")
将代码替换为
viewControllerd.title = "helo"
并且不需要以下代码:
init(title : String){
a = title
super.init(nibName: "SecondViewController", bundle: nil)
}
关于ios - 在 Storyboard中传递值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40014893/