在我的macOS应用程序中,我尝试通过编辑表格视图单元格来更新AppDelegate属性。
我创建了一个样例项目(带有数组控制器的Table View样例项目),使用了本文答案中的技巧。
我使用的是macOS Big Sur(11.6.8)和Xcode 12.5.1。如果需要的话,我很乐意提供一个源文件下载链接或通过电子邮件发送。当我试图在这篇文章中添加链接时,它被拒绝了。
Here's my AppDelegate script:
script AppDelegate
property parent : class "NSObject"
property msg : ""
-- IBOutlets
property theWindow : missing value
property tableViewData : missing value
property arrayController : missing value
property showTableViewData : missing value
on `applicationWillFinishLaunching_(aNotification)`
appInit()
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
return current application's NSTerminateNow
end applicationShouldTerminate_
on appInit()
set my msg to (current date & return & return & "Initializing…") as string
delay .5
initTableView()
set my msg to (current date & return & return & "Ready.") as string
delay .5
end appInit
on initTableView()
set my tableViewData to {}
set my tableViewData to {{adName:("C21 ad" as string), pageNumber:("001" as string)}, {adName:("ERA ad" as string), pageNumber:("002" as string)}}
end initTableView
on `showTableViewData_(sender)`
set my msg to (current date & return & return & "showing tableViewData....") as string
delay .5
set displayText to ""
repeat with thisRecord in tableViewData
display alert "adName: " & (adName of thisRecord as string) & return & "pageNumber: " & (pageNumber of thisRecord as string)
end repeat
set my msg to (current date & return & return & "Ready.") as string
delay .5
end `showTableViewData_`
end script
工作原理
正如你所看到的,我已经硬编码了两条记录,用于在初始化时填充tableViewData属性,这些属性依次显示在表视图中。由于某种原因,adName数据没有显示,但这个bug不是本文的主题。
App initialized
单击按钮读取tableViewData属性,迭代记录并通过警报显示它们(这样我们就可以看到它的内容)。
Record display
除了adName没有显示,到目前为止一切顺利。
接下来,我编辑第一条记录的pageNumber表格视图单元格(将其从"001"更改为"777"* 并按return *)。当我单击该按钮时,显示的第一条记录仍显示pageNumber值"001"(而不是我输入的"777"值)。
Record display after editing
以下是表格视图单元格属性、连接和绑定的一些快照:
AttributesConnectionsBindings
我尝试选择绑定设置"Continuously Updates Value",但似乎没有帮助;我的tableViewData属性没有用表格视图单元格中新输入的数据更新。
目前大多数开发者文档使用Obj-C或Swift而不是AppleScript和iOS或tvOS相关的。我使用Xcode 12.5.1是因为绑定UI元素到我的代码有问题。
谢谢你花时间看这个。
1条答案
按热度按时间kulphzqa1#
tableViewData
的内容不变,但content of arrayController
会更改。请尝试若要使其工作,请使用脚本对象而不是记录。