以编程方式从一个文件设置另一个文件中的值[Swift]
与:不一样,对我的处境没有帮助 当我按下一个文件中的按钮时(NSViewController) 我希望此文件显示bookName=“hello”的结果以编程方式从一个文件设置另一个文件中的值[Swift],swift,nsviewcontroller,Swift,Nsviewcontroller,与:不一样,对我的处境没有帮助 当我按下一个文件中的按钮时(NSViewController) 我希望此文件显示bookName=“hello”的结果 我缺少什么?您需要将popVC强制转换为PopoverViewController,以便设置bookName属性,因为NSViewController没有属性bookName: var popVC = NSStoryboard(name: "Main", bundle: nil)?.instantiateControllerWithId
我缺少什么?您需要将popVC强制转换为
PopoverViewController
,以便设置bookName
属性,因为NSViewController
没有属性bookName
:
var popVC = NSStoryboard(name: "Main",
bundle: nil)?.instantiateControllerWithIdentifier("PopoverViewController") as? PopoverViewController
然后,您将需要显示刚才使用presentViewController(\uu:animated:completion:)
此外,在您的
PopoverViewController
类中,您应该为bookName
使用var
,因为它是不变的。您也可以使用singleton:)不要使用singleton我没有意识到我也需要使用presentViewController
。非常感谢。
class PopoverViewController: NSViewController {
let bookName: String = ""
override func viewDidLoad() {
super.viewDidLoad()
println(bookName)
}
}
var popVC = NSStoryboard(name: "Main",
bundle: nil)?.instantiateControllerWithIdentifier("PopoverViewController") as? PopoverViewController