【发布时间】:2017-12-25 04:27:57
【问题描述】:
我想在以任何方式编辑文本字段文本时调用一个函数。
我是 swift 新手,而且代码墙并不能真正帮助我理解,这就是我在寻找答案时所能找到的全部内容。
有人显示自己 ctrl 单击文本字段并显示名为“编辑确实开始”或类似名称的已发送操作,但我只发送了名为“操作”的操作。我需要澄清一下。
编辑:这是针对 MacOS 应用程序的,UIKit 不起作用。
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var msgBox: NSTextField!
@IBOutlet weak var keyBox: NSTextField!
@IBOutlet weak var encBtn: NSButton!
@IBOutlet weak var decBtn: NSButton!
override func controlTextDidChange(_ obj: Notification) {
//makeKey()
keyBox.stringValue = "test"
}
override func controlTextDidBeginEditing(_ obj: Notification) {
print("Did begin editing...")
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func makeKey() {
keyBox.stringValue = "test"
}
}
【问题讨论】:
标签: swift function call nstextfield