[英]NSOpenPanel Sheet
这就是我将打开的面板显示为浮动窗口的方式。
有人可以帮助我将面板作为工作表运行吗? 窗口对象是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];
}
}
很简单,它就在文档中,尽管你可能已经错过了它,因为相关的方法实际上是NSSavePanel的一部分,NSOpenPanel继承了它。
假设您的目标是Snow Leopard或更好,因此可以访问块,只需用以下代码替换runModal调用:
[openPanel beginSheetModalForWindow:mWindow completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
// Do something.
}
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.