2015-06-19 97 views
1

有没有办法强制NSOpenPanel关闭,以便在调试时看到屏幕?在调试过程中,我无法在Xcode中看到代码,我也无法移动面板。NSOpenPanel在调试期间保持打开状态

这是我有:

- (IBAction)openImage:(id)sender { 
    NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"jpg", @"JPG", nil]; 

    NSOpenPanel *panel = [NSOpenPanel openPanel]; 
    [panel setCanChooseDirectories:NO]; 
    [panel setCanChooseFiles:YES]; 
    [panel setAllowsMultipleSelection:NO]; 
    [panel setAllowedFileTypes:fileTypes]; 

    [panel beginWithCompletionHandler:^(NSInteger result) { 
     if (result == NSFileHandlingPanelOKButton) { 

      self.image = [[NSImage alloc] initWithContentsOfURL:panel.URL]; 
      [panel close]; 


      [self doSomethingWithImage]; 

     }else{ 
     } 
    }]; 
} 

- (void) doSomethingWithImage { 
    // if I put a breakpoint here, 
    // the NSOpenPanel is still on the screen and I can't move it. 

} 

回答

0

一个简单的解决方法是在主队列调度-doSomethingWithImage所以执行-doSomethingWithImage之前完成处理结束(和对话框关闭)。

[panel beginWithCompletionHandler:^(NSInteger result) { 
    if (result == NSFileHandlingPanelOKButton) { 

     self.image = [[NSImage alloc] initWithContentsOfURL:panel.URL]; 
     [panel close]; 

     dispatch_async(dispatch_get_main_queue(), {() -> Void in 

     [self doSomethingWithImage]; 

     }); 

    }else{ 
    } 
}]; 
+0

我试过这个,它不适合我。 – Alex311

1

个人而言,我发现了两个方法:

  1. 如果你开始你的应用程序,无论是移动应用程序或Xcode到另一个桌面。所以,当你运行你的应用程序时,它会跳到另一个桌面(Xcode所在位置),当你到达一个中断点时,打开的面板不会妨碍Xcode

  2. 使用beginSheetModalForWindow:编码几乎相同,但面板在调试时不会隐藏部分Xcode。作为与窗口相关的选择面板运行OpenPanel。对于beginSheetModalForWindow,您必须指明相关窗口(通常是主窗口),这是唯一需要的附加编码。

+0

我改变了我的面板显示为一张表,它解决了我的这个问题。谢谢! – Alex311

相关问题