multithreading - 使用 applescriptobjc 实现 GDC

标签 multithreading cocoa applescript-objc

我正在制作这个简单的ApplescriptObjC cocoa 应用程序,只是为了让我理解多线程,它是一个文本字段和一个标签,我试图在文本字段中输入时实时更新标签,但是它只有在我按下回车键后才会更新,但不是实时更新,知道我如何才能做到这一点吗?这是代码。 谢谢

    script AppDelegate

    property parent : class "NSObject"
    property prgLabel: missing value
    property subjectFeild: missing value


    on applicationWillFinishLaunching_(aNotification)
        -- Insert code here to initialize your application before any files are opened  
    activate
  end applicationWillFinishLaunching_

    on applicationShouldTerminate_(sender)
        -- Insert code here to do any housekeeping before your application quits 
        return current application's NSTerminateNow
    end applicationShouldTerminate_

    on textChange_(sender)

        set SU to subjectFeild's stringValue() as string
        prgLabel's setStringValue_(SU)

    end textChange_


end script

最佳答案

1) 将文本字段的委托(delegate)设置为您的应用程序委托(delegate)。

2) 实现controlTextDidChange,每次编辑过程中文本字段发生变化时都会调用该函数。

script AppDelegate
    property parent : class "NSObject"

    -- IBOutlets
    property theWindow : missing value
    property prgLabel: missing value
    property subjectFeild: missing value

    on applicationWillFinishLaunching:aNotification
        subjectFeild's setDelegate:me
    end applicationWillFinishLaunching_


    on controlTextDidChange:notification
        prgLabel's setStringValue:subjectFeild's stringValue()
    end

end script

关于multithreading - 使用 applescriptobjc 实现 GDC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38863544/

相关文章:

不允许AppleScript应用程序发送击键

java - 如何为替代生产者和消费者方法编写 Java 多线程代码。它应该有 3 个生产者(P1、P2、P3)和 1 个消费者(C1)

Objective-C:按下按键时移动框架

objective-c - 在 Mac 应用程序中拦截 Command-Quit?

objective-c - 在 Objective C 中画饼图

excel - Applescript:写入没有旧文件名的新文件

appstore-sandbox - 脚本目标的权利 key /访问组

c++ - memory_order_relaxed 是否尊重同一线程内的数据依赖性?

php - 为什么 PHP 开发人员无法根据线程范围提供 setlocale 函数

multithreading - Haskell:TMVar 与 MVar