swift - 在自定义单元格中显示进度指示器的 Swift macOS 应用程序中,是否可以同步所有指示器的旋转?
问题描述
我有一个用 Swift / Objective-C 编写的 Cocoa 应用程序,我遇到的问题只是一个细节,但我认为这很重要。我有一个基于视图的NSOutlineView
数据源和委托驱动,并且我创建了一个NSTableViewCell
只包含旋转进度指示器的自定义。问题是,当应用程序窗口打开时,只有可见的旋转指示器同步旋转。如果我放大窗口并NSOutlineView
显示更多单元格,则新出现的旋转指示器不会同步旋转。这在逻辑上是正确的,因为我在NSOutlineView
委托方法中实例化了单元格:
outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView?
我的代码如下:
let view = outlineView.makeView(withIdentifier:NSUserInterfaceItemIdentifier.init("activityProgressTableViewCell"), owner: self) as! ProgressIndicatorTableCellView
view.unFinishedStatusIndicator.startAnimation(self)
所以我认为指标不同步是正常的,因为它们在不同的时刻开始旋转。任何人都可以建议一种模式来解决这个问题吗?任何帮助是极大的赞赏。谢谢。
PS 我知道我可以使用 Cocoa Bindings 而不是在指标上调用 startAnimation,这可以让我一次启动所有指标的动画,但是如何处理 NSOutlineView 子项中的旋转指标?
解决方案
Ok, I have found a possible solution, by using indeed Cocoa Bindings. In my main controller class, I have declared a property like this:
@objc dynamic var shouldStartFoldersIndicators: Bool = true
Then, in interface builder, I bind the animate binding of the progress indicator in the cell to that path of the main controller. Then, In this delegate method:
outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView?
When I need to display the spinning indicator cell, I set the Bool property to false, then to true. Unfortunately, this does not work:
self.shouldStartFoldersIndicators = false
self.shouldStartFoldersIndicators = true
In order to make it work, I had to defer the statements to the next running loop like this:
DispatchQueue.main.async {
self.shouldStartFoldersIndicators = false
DispatchQueue.main.async {
self.shouldStartFoldersIndicators = true
}
}
This works well, although I am afraid it could slow down the NSOutlineView redrawing. I thank you in advance for any better solution. Thanks
推荐阅读
- c# - 缺少主调度程序的模块。添加提供 Main 调度程序的依赖项,例如 'kotlinx-coroutines-android'
- julia - 将一列 DateTime 添加到现有数据框
- python - 使用python将多个excel附加到放置在文件夹中的单个excel中
- regex - 如何使用 bash 或正则表达式重命名具有多个字母和数字组合以及大小的多个文件?
- powershell - 测量对象没有输出正确的结果
- mesa-abm - 在 gis 形状文件的折线顶点处创建节点
- cobol - 在cobol的数组中查找重复项
- docker - 使用 Nextcloud docker image 时启用文档到 PDF 转换器
- php - WooCommerce 航运州选择
- java - 密码绑定凭据