NSTreeController的selectionIndexPaths在mouseDown后更新经常被中断

发布于 2024-11-03 13:13:01 字数 929 浏览 4 评论 0原文

问题背景:

我有一个 NSOutlineView,其中每个 tableColumn 以编程方式绑定到 NSTreeController 的排列对象,因此不需要绑定 SelectionIndexPaths。 NSTreeController的arrangedObjects的来源是一个mutableArray。我通过在主线程上执行 - (void)insertObject:(id)object atArrangedObjectIndexPath:(NSIndexPath *)indexPath; 动态地将所有节点添加到 NSTreeController 中。我已经重写了 NSOutlineView 的 mouseDown 事件,如下所示: - (void)mouseDown:(NSEvent *)event { /*...myMethods...*/ [super mouseDown:event];问题

当节点添加得非常快并且我在outlineView上执行mouseDown事件时,通常会发生下一种情况:

将节点添加到TreeController的线程会中断调用的序列(我猜)通过 mouseDown 事件,因此在 setSelectionIndexPaths: 之前调用 insertObject: atArrangedObjectIndexPath:。这就是为什么outlineView中的新选择消失了,而treeController仍然具有旧版本的selectedIndexPaths

我尝试了一种部分解决方案:阻止我的 insertObject: 方法(使用 @synthesized(outlineView)),以便它无法更改整个outlineView,但它经常线程冲突增加并且应用程序冻结。

有什么想法可以解决选择消失的问题吗?

Problem Background:

I have a NSOutlineView with every tableColumn binded programmatically to the NSTreeController's arrangedObjects so there is no need to bind selectionIndexPaths. The source of NSTreeController's arrangedObjects is a mutableArray. I'm adding all nodes to the NSTreeController dynamically by performing - (void)insertObject:(id)object atArrangedObjectIndexPath:(NSIndexPath *)indexPath; on main thread. I have overridden NSOutlineView's mouseDown event in the way like:
- (void)mouseDown:(NSEvent *)event { /*...myMethods...*/ [super mouseDown:event]; }

The Problem:

When the nodes are being added very fast and I perform the mouseDown event on the outlineView, then very often the next situation takes place:

the thread that adds nodes to TreeController interrupts the sequence (I guess) called by mouseDown event so insertObject: atArrangedObjectIndexPath: is called before then setSelectionIndexPaths:. That's why the new selection in outlineView disappears and treeController still has the old version of selectedIndexPaths.

I've tried one partial solution: blocked my insertObject: method (with @synthesized(outlineView)) so that it couldn't change the entire of outlineView, but it often rises in thread conflict and app freezes.

Are there any ideas how to solve the problem with disappearing selections?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似狗非友 2024-11-10 13:13:01

将数据源更新线程中的语句与主事件循环 GCD 线程同步。这样,mouseDown 事件处理和数据源更新就得到完全序列化:

dispatch_async(dispatch_get_main_queue(), ^{
  // data source update goes here
});

Synchronize the statements within the datasource update thread with the main-event-loop GCD thread. This way, mouseDown event handling and datasource updating get fully serialized:

dispatch_async(dispatch_get_main_queue(), ^{
  // data source update goes here
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文