在包含它的视图可见之前,如何使NSCollectionView完成绘图?

时间:2010-06-17 09:02:58

标签: cocoa nscollectionview

我正在尝试清理我的应用程序上的UI(为10.5构建),而且一件令人讨厌的事情是,当我交换到库时,我重新加载内容,显示项目的nscollectionview将旧内容淡出在淡入新的内容之前。我不介意旧/新项目的淡入/淡出,但是我编写视图交换的方式应该使库重新加载发生在包含nscollectionview的nsview插入之前主窗口。

之前有人遇到过这类问题吗?

以下是应用程序不同部分与库之间交换的简略版本:

在主控制器中:

-(void)setMainPaneToLibrary {
    if(viewState == VIEW_STATE_LIBRARY)
        return;
    [libraryController refreshDevices:self];
    [libraryController refreshLibraryContents];

    [menuController setSelectionToIndex:0];
    viewState = VIEW_STATE_LIBRARY;

    [self removeSubview]; //clear the area
    [mainPane addSubview:[libraryController view]];
}

在库控制器中:

-(void)refreshLibraryContents {
    [self loadLibraryContents:[rootDir stringByAppendingPathComponent:currentDir]];
}

-(void)loadLibraryContents:(NSString *)folderToLoad {

    int i;
    int currentSelection = [libraryArrayController selectionIndex]; //used to preserve selection and smooth folder changing

    [libraryArrayController setContent:nil];

    //expand the path to load
    folderToLoad = [folderToLoad stringByExpandingTildeInPath];

    NSFileManager * fileManager = [NSFileManager defaultManager]; 
    //load the files in the folder
    NSArray * contents = [fileManager directoryContentsAtPath:folderToLoad];

    //create two seperate arrays for actual files and folders - allows us to add them in order
    NSMutableArray * directories = [[NSMutableArray alloc] init];
    NSMutableArray * musicFiles = [[NSMutableArray alloc] init];

//... a load of stuff filling the file arrays ...

    for(i=0;i<[directories count];i++) {
    [libraryArrayController addObject:[directories objectAtIndex:i]];
    }
    for(i=0;i<[musicFiles count];i++) {
    [libraryArrayController addObject:[musicFiles objectAtIndex:i]];
    }

    if(currentSelection >= 0) {
    [libraryArrayController setSelectionIndex:currentSelection];
    }

    [directories release];
    [musicFiles release];   
}

1 个答案:

答案 0 :(得分:-1)

问题不在于集合视图还没有完成绘制,而是它动画添加和删除子视图。在您重新加载集合视图的内容时,可能会create a transaction禁用图层操作。清单2(暂时禁用图层的操作)显示了如何执行此操作。我没有测试过这个,所以我不知道这是否能满足您的需求,但这就是我要开始的地方。

相关问题