【发布时间】:2014-07-26 13:53:57
【问题描述】:
仅使用 Swift,这是我在 AppDelegate.swift 中的代码:
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var window: NSWindow
@IBOutlet var textField: NSTextView
@IBAction func displaySomeText(AnyObject) {
textField.insertText("A string...")
}
func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}
}
在界面构建器中,我连接了一个对象以接收来自按钮的输入,然后将输出转到文本视图。当我点击按钮时,我试图让文本视图填充一些文本。
我也尝试使用文本字段进行此操作,但没有收到错误,但听到“dong”错误声音并且没有执行任何其他操作。在 Objective-C 中,您必须使用 (assign) 参数才能根据我的理解使其工作。
我做错了什么?
【问题讨论】:
-
This question 描述了如何在 swift 中使用弱引用。
-
尝试在var前面使用weak,但没有区别。
标签: swift