简体   繁体   English

如何动态更新NSTreeController和NSOutlineView?

[英]How to dynamically update an NSTreeController and NSOutlineView?

When an outlineViewItem is expanded - 展开OutlineViewItem时-

 (void) outlineViewItemDidExpand:(NSNotification *)notification

-, I'm able to successfully add an object to the TreeController (log statements show the newly added object in the correct place of the hierarchy), but the OutlineView/UI isn't updating to reflect that insertion. -,我能够将对象成功添加到TreeController(日志语句在层次结构的正确位置显示了新添加的对象),但是OutlineView / UI并未更新以反映该插入。

To no avail, I've used 无济于事,我已经习惯了

  • [self.outlineView reloadItem:nil reloadChildren:YES] , [self.outlineView reloadItem:nil reloadChildren:YES]

  • [self.outlineView reloadData] , and even [self.outlineView reloadData]甚至

  • [self.outlineView setHidden:YES] then [self.outlineView setHidden:YES]然后
    [self.outlineView setHidden:NO]

to try to force reload the structure. 尝试强制重新加载结构。

This is all done programmatically in Objective-C. 所有这些都是在Objective-C中以编程方式完成的。

6 hours later, I got it. 6小时后,我明白了。

I needed to update the NSTreeController cache, which is achieved via the rearrangeObjects method. 我需要更新NSTreeController缓存,这是通过rearrangeObjects方法实现的。

So the answer to my question is: 所以我的问题的答案是:

[self.cloudDirectoryTreeController rearrangeObjects];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM