NSTableView内容未正确刷新(NSTableView contents not being refreshed properly)

编程入门 行业动态 更新时间:2024-10-10 14:21:24
NSTableView内容未正确刷新(NSTableView contents not being refreshed properly)

我已经设置了一个NSTableView ,它的列绑定到NSArrayController ,它从NSMutableDictionary实例的NSMutableArray ( Matches )获取其内容。

虽然事情正在发挥作用,但我遇到了这个问题:

当Matches数组更新时(这可能经常发生),表视图可能无法更新,但是当重新绘制视图时(例如,当我最小化并重新加载我的应用程序时)内容看起来很好。

有什么想法吗? 我怎么能让它重绘视图/更新内容?


提示:

我在更新我的Matches数组后也使用了[tableView reloadData] ,但没有效果。 这种情况不会一直发生,但有时......(即在内容显示之前,需要一些耐心并点击这里和那里或最小化应用程序)。

I've set up an NSTableView, whose columns are bound to an NSArrayController which gets its contents from an NSMutableArray (Matches) of NSMutableDictionary instances.

Although the thing is working, I'm experiencing this issue :

When the Matches array is updated (and this may happen quite really often), the Table View may fail to update, but when the view is redrawn (e.g. when I minimize and reload my application) the contents appear just fine.

Any ideas on that? How could I make it redraw the view / update the contents?


Hints :

I've also used [tableView reloadData] after updating my Matches array, but without effect. This doesn't happen ALL the time, but some times... (that is it takes some patience and clicking here-and-there or minimizing the app, before the contents show up).

最满意答案

听起来你正在直接操纵数组。 如果是这样,你可以“在控制器背后”这样做,可以这么说。 它没有得到阵列发生变化的任何通知。

理想情况下,数组控制器应该是负责从模型中添加和删除内容的对象; 你应该在控制器上使用addObject:和removeObject:或类似的),而不是数组本身。

如果做不到这一点,你可以在操作数组时发出KVO通知( willChangeValueForKey:和didChangeValueForKey: willChangeValueForKey: ; 这将使控制器获得更改。

It sounds like you're manipulating the array directly. If so, you're doing it "behind the controller's back", so to speak. It doesn't get any kind of a notification that the array has changed.

Ideally, the array controller should be the object responsible for adding and removing things from its model; you should be using addObject: and removeObject: (or similar) on the controller, not the array itself.

Failing that, you can issue KVO notices (willChangeValueForKey: and didChangeValueForKey:) when you manipulate the array; that will make the controller pick up the changes.

更多推荐

本文发布于:2023-08-06 10:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448369.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   内容   NSTableView   properly   refreshed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!