gpt4 book ai didi

swift - 在 cocoa 中,NSTextField 没有响应

转载 作者:可可西里 更新时间:2023-11-01 01:21:03 24 4
gpt4 key购买 nike

我只用源代码编写了 NSTextField。但是 NSTextField 不可点击,键盘事件也不起作用。

open class SearchBarView: ViewWrapper, NSTextFieldDelegate {
var textField: NSTextField!

---- TextField init
textField = NSTextField(frame: NSMakeRect(0, 0, 200, 60))
textField.isEditable = true
textField.font = NSFont.systemFont(ofSize: CGFloat(28.0))
textField.textColor = NSColor.gray
textField.isSelectable = true
textField.delegate = self

self.addSubview(self.textField)

---- func
open override func controlTextDidChange(_ notification: Notification)
{
Swift.print("asdasd")
let object = notification.object as! NSTextField
self.textField.stringValue = object.stringValue
}

enter image description here

我怎样才能得到键盘来修复它?

最佳答案

为了使 NSTextfield 正常工作,如果您使用的是自定义窗口,请检查您的窗口是否为 keyWindow() 和 mainWindow() YES。

- (BOOL)canBecomeKeyWindow {
return YES;
}
- (BOOL)canBecomeMainWindow {
return YES;
}

如果您有自定义窗口,请尝试您的 swift 代码。

关于swift - 在 cocoa 中,NSTextField 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43906299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com