Ios 在不同的故事板之间传递消息和/或对象
我有两个故事板,需要传递消息和对象。我知道如何在同一个故事板和.xib文件中完成,但不知道如何使用两个不同的故事板 我的代码是:Ios 在不同的故事板之间传递消息和/或对象,ios,swift,Ios,Swift,我有两个故事板,需要传递消息和对象。我知道如何在同一个故事板和.xib文件中完成,但不知道如何使用两个不同的故事板 我的代码是: var storyboard = UIStoryboard(name: "RecibosStoryboard", bundle: nil) var controller = storyboard.instantiateViewControllerWithIdentifier("RecibosStoryboard") as! UINavigationCo
var storyboard = UIStoryboard(name: "RecibosStoryboard", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("RecibosStoryboard") as! UINavigationController
self.presentViewController(controller, animated: true, completion: nil).
// If i do: var controller = storyboard.instantiateViewControllerWithIdentifier("RecibosStoryboard") as! = TableRecibosViewController -> fails ->cannot convert TablaRecibosViewController to UINavigationController
// If i do:
/* var controller = storyboard.instantiateViewControllerWithIdentifier("RecibosStoryboard") as! UINavigationController
let vartest: TablaRecibosTableViewController = TablaTablaRecibosTableViewController()
prueba.inicioPrueba(str, strPrueba2: str2) -> two objects are nill
self.presentViewController(controller, animated: true, completion: nil).
Two objects are nill*/
我的第二个故事板是“RecibosStoryboard”,只有一个视图,该视图的类是TablaRecibosViewController,并且有一个构造函数方法:
class TablaRecibosTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tablaRecibos: UITableView!
var pruebaMansajes: String?
var pruebaMansajes2: String?
var arrayOfObjectsCellRecibos: [ObjectTableRecibos] = [ObjectTableRecibos] ()
override func viewDidLoad() {
super.viewDidLoad()
tablaRecibos.dataSource = self
tablaRecibos.delegate = self
println("Pruebas satisfactorias1 \(pruebaMansajes) \(pruebaMansajes2)")
}
func inicioPrueba(strprueba1:String, strPrueba2:String){
pruebaMansajes = strprueba1
pruebaMansajes2 = strPrueba2
}
当我执行应用程序或崩溃或打印两个对象时=nil
我找不到办法。非常感谢。问题是“无法将TablaRecibosViewController转换为UINavigationController”。您的TablaRecibosViewController嵌入到UINavigationController中。请尝试以下操作:
if let recibosViewController = (storyboard.instantiateViewControllerWithIdentifier("RecibosStoryboard") as? UINavigationController).viewControllers.first as? TablaRecibosTableViewController {
recibosViewController.pruebaMensajes = "Hola mundo"
}
您正在创建TablaTablaRecibosTableViewController()的新实例,该实例与情节提要无关,因此表视图为nil,它崩溃了 我不能用你的密码。我别无选择,只能把这个观点放在同一个故事板上:(。出于好奇,如果有人知道怎么做,我想这对任何人都有帮助。谢谢