【发布时间】:2020-07-30 08:01:57
【问题描述】:
我正在尝试创建一个窗口,用户可以在其中输入产品的激活密钥,我通过创建 5 个不同的 NSTextField 来完成此操作,如图所示。
我要补充的是the ability for the cursor to move to the next text field once a character count has been reached (which is 5 characters maximum per textfield)。
我确实找到了此代码,但它是针对 IOS 的,因为我不知道要进行哪些更改(Code for the IOS version)
这是我尝试过的代码
override func viewDidLoad() {
super.viewDidLoad()
ActKeyOne.textDidChange(Notification.Name.init(rawValue: "textchanged"))
}
它给出了错误:
Cannot convert value of type 'Notification.Name' (aka 'NSNotification.Name') to expected argument type 'Notification'
【问题讨论】:
-
使用文本字段通知计算每个文本字段中的字符数。
-
textDidChangeNotification&makeFirstResponder(_:)。尝试一下,如果它不适合您,请使用不适合您的代码编辑您的问题。 -
您可以使用委托和controlTextDidChange(_:),而不是
textDidChangeNotification。 -
看起来 controlTextDidChange( :) 效果更好,谢谢大家
标签: swift macos user-interface cocoa