NSPanel
The NSPanel class implements a special kind of window (known as a panel), typically performing an auxiliary function.
NSPanel类是一种特殊的window类,主要用于实现一些辅助功能。
NSOpenPanel
The NSOpenPanel class provides the Open panel for the Cocoa user interface. Applications use the Open panel as a convenient way to query the user for the name of a file to open.
NSOpenPanel类为Cocoa用户界面提供打开面板的操作。应用使用面板作为一种便捷方式,询问用户需要打开的文件名。
Overview
In a sandboxed environment, Open panels are drawn in a separate process by the powerbox, not by AppKit itself. When the user chooses a file to open, macOS adds that file to the app’s sandbox.
在沙盒环境里,电源箱将面板拖进一个单独的进程。当用户选择打开一个文件时,macOS系统会将这个文件添加到app沙盒里。
var canChooseFiles: Bool
A Boolean that indicates whether the panel allows the user to choose files to open.
canChooseFiles——布尔值,表示面板是否允许用户选择打开文件。
var canChooseDirectories: Bool
A Boolean that indicates whether the panel allows the user to choose directories to open.
canChooseDirectories——布尔值,表示面板是否允许用户选择打开文件夹。
使用示例代码:
```
- (IBAction)push:(NSButton *)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.canChooseFiles = YES;
[panel beginSheetModalForWindow:_window completionHandler:^(NSInteger result)
{
if (result == NSModalResponseOK)
{
NSArray *urls = panel.URLs;
for (NSURL *url in urls)
{
NSLog(@"url = %@",url);//选择文件的本地路径
NSString *str_FilePath = [NSString stringWithFormat:@"%@",url];
self.TF_ShowFilePath.stringValue = [str_FilePath substringFromIndex:7];
}
}
}];
NSLog(@"openPanel");
}
```
[### 贴上本人翻译的一本后现代小说地址,亚马逊已上架,欢迎阅读,吐槽~哈 ###](https://www.jianshu.com/p/36a9ca8c4524)
网友评论