2013-01-22 22 views
0

我想使用NSOpenPanel调出打开的文件页面。它工作正常,在大多数情况下,除了3件事情:NSOpenPanel代理怪异

  1. 的第一个问题是,侧栏不会出现,但我仍然可以点击它。

  2. 第二个问题是,当我切换到文件比以前文件少的文件夹时,屏幕不会被清除,并且一些以前的文件仍然出现,尽管它们是不可点击的。

  3. 当我尝试切换到列视图时,应用程序崩溃。但所有3个其他意见工作得很好。

这里的崩溃日志:

AppKit`-[NSTableView setVerticalMotionCanBeginDrag:]: 
0x7fff91d4f899: pushq %rbp 
0x7fff91d4f89a: movq %rsp, %rbp 
0x7fff91d4f89d: movq 7385076(%rip), %rax  ; TrustKeychains::systemKcHandle() + 92 
0x7fff91d4f8a4: movq (%rax,%rdi), %rax 
0x7fff91d4f8a8: movq 7385193(%rip), %rcx  ; tp_policyTrustSettingParams + 92 
0x7fff91d4f8af: movl $4292870143, %edi 
0x7fff91d4f8b4: andl (%rax,%rcx), %edi <- Crash points here with EXC_BAD_ACCESS (code=1, address = 0x18) 
0x7fff91d4f8b7: shll $21, %edx 
0x7fff91d4f8ba: andl $2097152, %edx 
0x7fff91d4f8c0: addl %edi, %edx 
0x7fff91d4f8c2: movl %edx, (%rax,%rcx) 
0x7fff91d4f8c5: popq %rbp 
0x7fff91d4f8c6: ret  

崩溃日志说,飞机坠毁在线程1

我想知道是否有人知道如何解决它。这里是我的代码

-(IBAction)openDialog:(id)sender{ 
NSWindow *window = [[viewArray objectAtIndex:currentIndex] window]; 

NSOpenPanel *openDialog = [NSOpenPanel openPanel]; 
[openDialog setCanChooseFiles:YES]; 
[openDialog setCanChooseDirectories:NO]; 
NSString *homeString = [NSString stringWithFormat:@"file://localhost%@",NSHomeDirectory()]; 
[openDialog setDirectoryURL:[NSURL URLWithString:homeString]]; 
NSArray *fileTypes = [[NSArray alloc] initWithObjects:@"xcodeproj", nil]; 
[openDialog setAllowedFileTypes:fileTypes]; 

[openDialog beginSheetModalForWindow:window completionHandler:^(NSInteger result){ 
    if (result == NSFileHandlingPanelOKButton){ 
     NSURL *doc = [openDialog URL]; 
     [[NSWorkspace sharedWorkspace] openFile:[doc relativePath]]; 
    } 
}]; 

}

我把完全相同的代码在不同的XCode项目,它工作得很好,所以我不太清楚问题出在哪里。谢谢!

+0

听起来像堆栈损坏。 – trojanfoe

+0

什么是堆栈损坏?对不起,我还在学习如何使用Objective-C进行编码 – user1998511

回答

0

我发现了这个问题。事实证明,在我的项目中,我重新定义了NSTableView,导致了所有的错误。