zoukankan      html  css  js  c++  java
  • 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");
            }
        }];

  • 相关阅读:
    Java单例模式深入详解
    深入理解Java的接口和抽象类
    java中为什么要给类使用代理?它有哪些好处?
    Log4j--java日志
    Log4j rootLogger配置
    selenium之 下拉选择框Select
    关于弹框
    spring controller接口中,用pojo对象接收页面传递的参数,发现spring在对pojo对象赋值时,有一定顺序的问题
    navicat mysql报错误:2013 Lost connection to MySQL server during query
    记录一次mysql导入千万条测试数据过慢的问题!
  • 原文地址:https://www.cnblogs.com/v-BigdoG-v/p/7602620.html
Copyright © 2011-2022 走看看