本文介绍了NSOutlineView reloadItem:没有效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在基于视图的 c> [myOutlineView reloadData] 。



<但它从不调用 - (NSView *)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item

   - (void)reloadOutlineViewObject 
{
// [myOutlineView reloadData]; //重新加载数据只是罚款,但是ressource-hungry
NSLog(@%d,[myOutlineView rowForItem:myOutlineViewItem]; //确保我的对象是一个项目的outlineView,它是!
[myOutlineView reloadItem:myOutlineViewItem];
}

p>

UPDATE



正如评论中指出的,我的outlineView是基于视图的。



UPDATE 2



尝试一些东西让我意识到我重载的对象是一个二级对象(对象树)调用 reloadItem:firstLevelObject reloadChildren:YES 可以工作。



有可能我们只能调用reloadItem:on第一级对象?在我的情况下,这将是非常低效的(我只有一个两级项目和大量的第二级)。

  nil  - > firstLevelA  - > secondLevel1 
- > secondLevel2
- > firstLevelB - > secondLevel3
- > secondLevel4



在同一时间尝试子类化NSOutlineView并重写 reloadItem:。



UPDATE 3



我看了一下获得开始,并认为我需要编写的代码覆盖reloadItem将安静沉重。任何人都要确认?

解决方案

我遇到了同样的问题与基于视图的大纲视图,其中调用 -reloadItem:似乎只是不做任何事情。这肯定看起来像一个大bug,虽然文档没有明确说, reloadItem 将重新获取该行的视图。



我的解决方法是调用 NSTableView 的 -reloadDataForRowIndexes:columnIndexes:预期,触发对该项的 -outlineView:viewForTableColumn:item:委托方法的调用。您可以通过调用 -rowForItem:并传入要重新加载的项目来获取需要重新加载的行。


I'm trying to release some strain on a view-based NSOutlineView for which I changed a single item property and which I initially reloaded just fine using [myOutlineView reloadData].

I tried [myOutlineView reloadItem: myOutlineViewItem] but it never calls - (NSView *)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item and consequently the data is not updated.

-(void)reloadOutlineViewObject
{
    //[myOutlineView reloadData];   //Reload data just fines but is ressource-hungry
    NSLog(@"%d",[myOutlineView rowForItem:myOutlineViewItem]; //Making sure my object is an item of the outlineView, which it is !
    [myOutlineView reloadItem:myOutlineViewItem];
}

Am I missing something here ?

UPDATE

As pointed out in the comments, my outlineView is view-based.

UPDATE 2

Trying out some stuffs made me realized that the object I am reloading is a second-level object (cf object tree) and calling reloadItem:firstLevelObject reloadChildren:YES does work.

Would it be possible that we can only call reloadItem: on first-level object ? That would be highly inefficient in my case (I only have one two level item and plenty of second level) !

nil ->firstLevelA ->secondLevel1
                  ->secondLevel2
    ->firstLevelB ->secondLevel3
                  ->secondLevel4

Gonna try to subclass NSOutlineView and rewrite reloadItem: in the mean time.

UPDATE 3

I took a look at NSOutlineView in Cocotron to get start and felt that the code I needed to write to overwrite reloadItem would be quiet heavy. Anyone to confirm ?

解决方案

I encountered this same problem with a view-based outline view, where calling -reloadItem: seems to just not do anything. This definitely seems like a big bug, though the documentation doesn't explicitly say that reloadItem will reacquire the views for that row.

My workaround was to call NSTableView's -reloadDataForRowIndexes:columnIndexes: instead, which seems to work as expected, triggering a call to the -outlineView:viewForTableColumn:item: delegate method for just that item. You can get the row that needs to be reloaded by calling -rowForItem: and passing in the item you want to reload.

这篇关于NSOutlineView reloadItem:没有效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 06:27