【发布时间】:2018-06-05 09:09:27
【问题描述】:
很抱歉这个简单的问题,但我不明白如何在我在 Main.storyboard 中构建的 GUI 中获取对我的组件的引用。这就是它现在的样子:
func applicationDidFinishLaunching(_ aNotification: Notification) {
let myWindowController = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil).instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "abcd")) as! MyMainWindow
myWindowController.showWindow(self)
左上角的视图控制器是我的“MyMainWindow”(NSWindowController),ID 为“abcd”。现在,我想在代码中的 Tab1 中访问类似此复选框的组件:
在 Android 中,即您执行 findViewById(R.id.idOfTheComponent) 之类的操作,但我已经看到在 Xcode 中您可以 Ctrl-Drag 组件到 ViewController 中。但是,当我尝试将复选框拖到我的 ViewController.swift 类中时,我没有工作。有人可以帮忙吗?
【问题讨论】:
-
ViewController是tab 1的视图控制器的类吗?您不能将复选框连接到不同场景的视图控制器。
标签: swift xcode cocoa viewcontroller nswindowcontroller