0
我有一個視圖控制器實例化新的窗口控制器。 我需要將一個對象傳遞給該窗口控制器的視圖控制器。 這是我到目前爲止有:如預期的那樣顯示從故事板實例化的視圖控制器鑄造失敗
let storyboard = NSStoryboard(name: "Main", bundle: nil)
if let windowController = storyboard.instantiateController(withIdentifier: "customerEditWindowController") as? NSWindowController
{
let viewController = windowController.contentViewController as! EditCustomerViewController
viewController.customer = customer // (An object)
windowController.window?.makeKeyAndOrderFront(self)
}
窗口,然後Xcode的陷阱與錯誤調試器:
Could not cast value of type 'NSViewController' (0x7fffd1dcc4e0) to 'Inventory2.EditCustomerViewController' (0x100011660).
我很困惑,因爲我EditCustomerViewController延伸NSViewController。
class EditCustomerViewController: NSViewController
1)爲什麼不能NSViewController被轉換爲EditCustomerViewController?
2)有沒有更好的方法來獲取數據到新的視圖控制器?
哇!偉大的目標。謝謝! –