开发者

NSOutlineView not refreshing/displaying all content

开发者 https://www.devze.com 2023-01-26 15:08 出处:网络
I have an NSOutlineView, with its content bound to an appropriate NSTreeController. It works perfectly well, except when my app loads, only about half of the content of the NSOutlineView displays.

I have an NSOutlineView, with its content bound to an appropriate NSTreeController. It works perfectly well, except when my app loads, only about half of the content of the NSOutlineView displays.

If I cmd+tab away and back, all the content displays. If I click the blank rows where I know there should be content, the text in the row I clicked suddenly appears. So the content's there, it's just not refreshing prope开发者_开发问答rly. I guess I need to send the NSOutlineView a needsDisplay message or something similar, but I'm not quite sure where.

This seems pretty illogical to me - the NSOutlineView should surely be able to display its content properly when bound. Is there something obvious that I'm missing?


According to the apple documentation, you should always send -reloadData to the outline view after it's been created. In your case that would be wherever your NIB has finished loading (-awakeFromNib? -applicationDidFinishLaunching? Depends on the implementation).

Have you sent the outline view a -reloadData message? This always works for me.


I gave up on binding this NSOutlineView and switched to using an NSOutlineViewDataSource instead. I suspect some part of my code wasn't fully KVO compliant and this was making it not work properly.


When using KVO, you can cause change notifications by sending willChangeValueForKey: and didChangeValueForKey: to the object (most likely a controller) that owns the property that's bound to the NSOutlineView. These messages can be sent from an awakeFromNib: or applicationDidFinishLaunching: handler, just like reloadData.

If you add (minimal) sample code to your question, we might be able to figure out whether that will fix the problem, or whether there's something else that needs addressing.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号