我有許多視圖控制器,遍佈在許多故事板上。將數據傳遞給「未知」視圖控制器
當只知道viewcontroller標識符時,有什麼方法可以將數據傳遞給viewcontroller。
的視圖控制器標識符和故事板名稱從plist中讀取,並且的ViewController裝載這樣的:
let storyboard = UIStoryboard(name: plistdata.storyboard, bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: menuItem.identifier)
navigationController?.pushViewController(vc, animated: true)
由於我不能投射的視圖控制器作爲適當的類,我不能設置數據。可以在課堂上從一個字符串鑄造,像
let vc = storyboard.instantiateViewController(withIdentifier: menuItem.identifier) as! ClassFromString("MyDestinationViewController")
或者會是一個更好的辦法有數據模型跟蹤哪些視圖 - 控制被推,並儘快取回在目標視圖 - 控制所需的數據它加載?