在ApplescriptObjC中,当使用绑定来连接视图和属性时,有时会出现文本视图不更新的问题。这个问题的解决方法是在绑定的属性中添加一个无关的数值属性,并在代码中手动更新它。这将强制文本视图更新,并显示新的文本。以下是一个示例代码,演示如何解决这个问题:
script AppDelegate
property parent : class "NSObject"
property theText : ""
property dummyProperty : 0
-- Step 1: Connect text view to 'theText' property using bindings in Interface Builder
on buttonClicked_(sender)
set theText to "Hello World!"
-- Step 2: Update dummyProperty to trigger update of text view
-- Note: Property observer is not called when 'theText' is updated via bindings
set dummyProperty to dummyProperty + 1
end buttonClicked_
end script
一旦你添加了一个无关的属性,并在代码中更新它,就可以随意更新你的文本视图了。