0
我试着用我的程序使用NSOpenPanel
,它根本不起作用,因为NSOpenpanel不在主线程上运行。主线程上的NSOpenPanel不起作用
这里是我的代码
NSString *strURL;
NSOpenPanel *fileContents;
NSURL *panelURL;
NSArray *fileTypes = [NSArray arrayWithObjects:@"strings", @"STRINGS", nil];
fileContents = [NSOpenPanel openPanel];
[fileContents setCanChooseDirectories:NO];
[fileContents setCanChooseFiles:YES];
[fileContents setAllowedFileTypes:fileTypes];
[fileContents setAllowsMultipleSelection:NO];
NSInteger openPanelButton = [fileContents runModal];
if(openPanelButton == NSModalResponseOK)
{
panelURL = [fileContents URL];
strURL = panelURL.absoluteString;
}
NSArray *linesReadOnly = [strURL componentsSeparatedByString:@"\n"];
我都尝试以下代码:
[fileContents performSelectorOnMainThread:@selector(runModal) withObject:nil waitUntilDone:YES];
和
dispatch_sync(dispatch_get_main_queue(), ^{
//do UI stuff
});
它只是不工作的时候得到这个在主线程。我做错了什么?
就Objective-C而言,NSOpenPanel的主题已经在这里进行了彻底讨论。没有新东西。 –