我是 Swift 和 Mac App 的新手。所以我今天正在写一个 Mac 应用程序,在搜索了很多之后,我仍然困惑如何从另一个类访问 IBOutlet。
我正在使用 StoryBoard path mirror,我的 ViewController 中有两个 NSTextField 。我Path.swift为第一个 NSTextField创建了一个自定义类,path以了解输入的文本何时path发生更改。
class Path: NSTextField, NSTextFieldDelegate
{
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
// Drawing code here.
self.delegate = self
}
var current = ""
override func controlTextDidChange(obj: NSNotification)
{
current = self.stringValue
println("Current is \(current)")
}
}
Run Code Online (Sandbox Code Playgroud)
ViewController.swift 中定义了两个出口
class ViewController: NSViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the …Run Code Online (Sandbox Code Playgroud)