nsmenu项中的textfield与init一起使用时给出奇怪的行为

时间:2019-04-26 22:13:29

标签: swift macos cocoa

我正在将文本字段添加到nsmenuitem 当我单击文本字段时,它适用于第一个 我单击一次,但是该项目变得不可点击

它也不会在侧面显示菜单项标题

class charPoolboxForMenuItem: NSTextField,NSTextFieldDelegate{

override init(frame: CGRect) {
    super.init(frame: frame)
    self.frame = CGRect(x: 30, y: 0, width: 200, height: 22)
    self.placeholderString = "Character Pool"
    self.stringValue = UserDefaults.standard.value(forKey: "charPoolBox") as! String
    self.delegate = self
}

required init?(coder: NSCoder) {
    super.init(coder: NSCoder.init())
    fatalError("init(coder:) has not been implemented")
}
override func textDidChange(_ notification: Notification) {if self.currentEditor()?.selectedRange != nil{UserDefaults.standard.set(self.stringValue, forKey: "charPoolBox")}}

}

0 个答案:

没有答案
相关问题