Is there a way to force the NSOpenPanel to close so I can see the screen while debugging? I can't see code behind it in Xcode while debugging and I can't move the panel either.
This is what I have:
- (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.
}
A simple workaround is to schedule
-doSomethingWithImage
on the main queue so the completion handler finishes (and the dialog closes) before-doSomethingWithImage
is executed.