我有一组按钮和一组关联的NSTextViews(嵌入在NSScrollViews中),所有这些都是以编程方式创建的。所有这些都在程序(日历)中编译并且可以正常工作。
但是,我想点击一个按钮,使关联的文本字段表现得像我直接在其中单击一样(光标和焦点环出现,它接受文本)。现在,在开始输入文本之前,我必须单击按钮和文本框。
似乎“makeFirstResponder”应该按照我的意愿行事,但它不会编译,因为我试图这样做。
以下是相关代码:
(全部在一个视图控制器中)
全球宣言:
var arrayOfButtons:[NSButton] = []
var arrayOfFields: [NSTextView!] = []
var arrayOfWindows: [NSScrollView!] = []
创建字段数组:
var i = 0
var myLocalText: NSTextView! = NSTextView(…
var myLocalWindow: NSScrollView! = NSScrollView(…
for i = 0; i <= 6; i++ {
var myLocalText: NSTextView! = NSTextView(…
var myLocalWindow: NSScrollView! = NSScrollView(…
view.addSubview(myLocalWindow)
myLocalWindow.hasVerticalScroller = false
myLocalWindow.focusRingType = NSFocusRingType(rawValue: UInt(2))! // I didn’t get a focus ring until I did this
myLocalWindow.addSubview(myLocalText)
myLocalWindow.documentView = myLocalText
myLocalText.editable = true
myLocalText.selectable = true
myLocalText.verticallyResizable = true
self.arrayOfFields.append(myLocalText)
}
响应单击按钮的例程:
…
view.makeFirstResponder(arrayOfFields[tag]) // THIS IS THE SUBJECT OF MY QUESTION
// IT GIVES A COMPILER ERROR AS FOLLOWS: “Cannot invoke ‘makeFirstResponder’ with an argument list of type ’NSTextView’”
// as far as I can tell from the documentation, makeFirstResponder should accept an argument type of NSResponder, and NSTextView should inherit from that
答案 0 :(得分:0)
在Mac OS X中,makeFirstResponder
是NSWindow方法,而不是NSView方法。