swift – 不能形成对类NSTextView的实例的弱引用
发布时间:2020-12-14 05:20:43 所属栏目:百科 来源:网络整理
导读:只使用 Swift,这是我在AppDelegate.swift中的代码: import Cocoaclass AppDelegate: NSObject,NSApplicationDelegate { @IBOutlet var window: NSWindow @IBOutlet var textField: NSTextView @IBAction func displaySomeText(AnyObject) { textField.inser
只使用
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 } } 在界面构建器中,我有一个对象挂起来从一个按钮接收输入,然后输出到文本视图.当我点击按钮时,我正在尝试使文本视图填充一些文本. 我也尝试了一个文本字段,并没有得到错误,但有一个“东”错误的声音,它没有做任何其他的事情.在Objective-C中,您必须使用(assign)参数才能使其从我所理解的方面工作. 我究竟做错了什么?
使用@IBOutlet var scrollView:NSScrollView而不是@IBOutlet var textField:NSTextView.
然后在scrollView中创建一个返回documentView的属性. import Cocoa class AppDelegate: NSObject,NSApplicationDelegate { @IBOutlet var window: NSWindow @IBOutlet var scrollView: NSScrollView var textField: NSTextView { get { return scrollView.contentView.documentView as 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 } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |