objective-c - 在用户键入时更新标签 使用 Cocoa-Applescript

标签 objective-c xcode macos cocoa applescript

我一直在寻找这个问题的答案有一段时间了。我已经看过有关如何在 Cocoa-Applescript 环境之外执行此操作的示例,但我没有足够的知识来将其适应 Applescript 版本。

当用户在文本字段中输入内容时,我尝试更新用户界面上的标签。我的应用程序是一个使用 Xcode 5.0 的基于 Cocoa-Applescript 的应用程序(这是作为 Mac 应用程序开发的,而不是 iOS)。

我已经尝试过:

on controlTextDidChange_(aNotification) -- a text field changed, so check it out
    set thisTextField to aNotification's object() -- the current control being changed
    set theText to thisTextField's stringValue()
    -- whatever
end controlTextDidChange_

但这似乎对我不起作用,它仅在用户按 Enter 或将焦点更改到另一个元素后更新 - 我需要在用户键入时更新它。我还看到过在 iOS 应用程序中完成此操作的示例:

[textField addTarget:self action:@selector(textViewDidChange) forControlEvents:UIControlEventEditingChanged];

但我不知道如何将其改编成 Applescript!

任何帮助都会很棒!

最佳答案

您可以使用 controlTextDidChange 来完成此操作。您只需在 Interface Builder 中将 NSTextField 的委托(delegate)设置为 App Delegate 对象,然后将如下内容添加到您的 AppDelegate.applescript 文件中:

property aTextField : missing value
property aTextField2 : missing value

property aTextLabel : missing value


    on controlTextDidChange_(aNotification)

       if aNotification's object() is aTextField then
           set newText to aTextField's stringValue()
           aTextLabel's setStringValue_(newText)
       end if


       if aNotification's object() is aTextField2 then
           set newText to aTextField2's stringValue()
           aTextLabel's setStringValue_(newText)
       end if

    end controlTextDidChange_

关于objective-c - 在用户键入时更新标签 使用 Cocoa-Applescript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19649484/

相关文章:

macos - 为什么我的 Split View会这样,我该如何解决?

bash - 为什么这个别名在 .bash_profile 脚本中不起作用?

objective-c - 有没有快速的方法知道 UITableView 中设备屏幕外的单元格是什么?

iphone - 外部 UITableView 委托(delegate)如何隐藏 UISearchBar 键盘?

ios - Objective-C - 尝试播放声音

iphone - 应用程序仅在iPhone设备上崩溃而不在模拟器中崩溃

ios - 调用 viewDidLoad

macos - Postgres.app : pg_restore hangs

objective-c - 自迁移以来导航栏和表格 View 之间的黑条

c++ - XCode:如何为单个源文件添加预处理器定义?