我正在尝试清理我的应用程序(为 10.5 构建)上的 UI,而一件相当烦人的事情是,当我切换到库时,我重新加载了内容,并且显示项目的 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];
}