NSOpenPanel-Object C组件-打开对话框-选择文件/文件夹获得路径
Posted 笑面浮屠
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NSOpenPanel-Object C组件-打开对话框-选择文件/文件夹获得路径相关的知识,希望对你有一定的参考价值。
1. NSOpenPanel的beginWithCompletionHandler:^(NSInteger result),打开文件对话框时,对话框出现在屏幕的中央。
NSMutableArray * fileURLArray = [[NSMutableArray alloc] init]; NSOpenPanel * mySelectPanel = [NSOpenPanel openPanel]; [mySelectPanel setCanChooseDirectories:YES]; [mySelectPanel setCanChooseFiles:YES]; [mySelectPanel setCanCreateDirectories:YES]; [mySelectPanel setAllowsMultipleSelection:YES]; [mySelectPanel setResolvesAliases:YES]; //界面出现在电脑屏幕中央 [mySelectPanel beginWithCompletionHandler:^(NSInteger result) { if (result == NSModalResponseOK) { NSLog(@"OK"); for (NSURL * url in [mySelectPanel URLs]){ NSString * path = [NSString stringWithString:[url path]]; //path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [fileURLArray addObject:path]; NSLog(@"%@", path); } for (NSString * a in fileURLArray) { NSLog(@"%@", a); } NSLog(@"%@", fileURLArray); } else if (result == NSModalResponseCancel) { NSLog(@"Cancel"); } else if (result == NSModalResponseStop) { NSLog(@"Stop"); } }];
2. NSOpenPanel的beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result),打开文件对话框时,对话框依附在操作界面下。
NSMutableArray * fileURLArray = [[NSMutableArray alloc] init]; NSOpenPanel * mySelectPanel = [NSOpenPanel openPanel]; [mySelectPanel setCanChooseDirectories:YES]; [mySelectPanel setCanChooseFiles:YES]; [mySelectPanel setCanCreateDirectories:YES]; [mySelectPanel setAllowsMultipleSelection:YES]; [mySelectPanel setResolvesAliases:YES]; //对话框依附在操作界面下 [mySelectPanel beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result) { if (result == NSModalResponseOK) { NSLog(@"OK"); for (NSURL * url in [mySelectPanel URLs]){ NSString * path = [NSString stringWithString:[url path]]; //path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [fileURLArray addObject:path]; NSLog(@"%@", path); } for (NSString * a in fileURLArray) { NSLog(@"%@", a); } NSLog(@"%@", fileURLArray); } else if (result == NSModalResponseCancel) { NSLog(@"Cancel"); } else if (result == NSModalResponseStop) { NSLog(@"Stop"); } }];
以上是关于NSOpenPanel-Object C组件-打开对话框-选择文件/文件夹获得路径的主要内容,如果未能解决你的问题,请参考以下文章
OpenFileDialog的使用-----C#程序设计 01
我安装vs2017时安装的c++没安mfc请问怎么单独添加这个组件
从 IClassFactory 为 CLSID 为 {00024500-0000-0000-C000-000000000046} 的 COM 组件创建实例失败,原因是出现以下错误: 8001010a解