gpt4 book ai didi

xcode - NSOpenPanel 在调试期间保持打开状态

转载 作者:行者123 更新时间:2023-12-03 17:02:10 27 4
gpt4 key购买 nike

有没有办法强制 NSOpenPanel 关闭,以便我可以在调试时看到屏幕?调试时我在 Xcode 中看不到其背后的代码,也无法移动面板。

这就是我所拥有的:

- (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.

}

最佳答案

一个简单的解决方法是在主队列上安排 -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{
}
}];

关于xcode - NSOpenPanel 在调试期间保持打开状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30948506/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com