我已经设置了一个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.
更多推荐
发布评论