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");
            }
        }];

  • 相关阅读:
    Hibernate持久化对象修改id重新保存的办法
    hibernate实现数据实体复制保存
    MySQL 语句中执行优先级——and比or高
    Unity3D研究院之静态自动检查代码缺陷与隐患
    MVC模式在游戏开发的应用
    Unity3D的LightProbe动态光探头用法介绍
    高达渐出现效果Shader
    Unity3D战争迷雾效果
    从3D Studio Max导入物体 Importing Objects From 3D Studio Max
    从maya导入物体 Importing Objects From Maya
  • 原文地址:https://www.cnblogs.com/v-BigdoG-v/p/7602620.html
Copyright © 2011-2022 走看看