这就是我将打开的面板显示为浮动窗口的方式。
有人能帮我把面板作为工作表运行吗?窗口对象是mWindow。我使用的大部分标准代码都被折旧了。
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"mp3", @"mp2", @"m4a", nil];
[openPanel setAllowsMultipleSelection: NO];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanCreateDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setAllowedFileTypes:fileTypes];
NSString * filePath = @"~/Desktop";
filePath = [filePath stringByExpandingTildeInPath];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
[openPanel setDirectoryURL:fileURL];
NSInteger clicked = [openPanel runModal];
if (clicked == NSFileHandlingPanelOKButton) {
for (NSURL *url in [openPanel URLs]) {
NSString *urlString = [url path];
[input setStringValue:urlString];
NSString *myString = [input stringValue];
NSString *oldPath = [myString lastPathComponent];
[inputDisplay setStringValue:oldPath];
}
}发布于 2012-02-10 05:11:43
非常简单,它就在文档中,尽管您可能遗漏了它,因为相关方法实际上是NSOpenPanel继承的NSSavePanel的一部分。
假设您的目标是雪豹或更好的,因此可以访问块,那么只需用以下代码替换您的runModal调用:
[openPanel beginSheetModalForWindow:mWindow completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
// Do something.
}
}];https://stackoverflow.com/questions/9218679
复制相似问题