码迷,mamicode.com
首页 > 其他好文 > 详细

NSOpenPanel-Object C组件-打开对话框-选择文件/文件夹获得路径

时间:2017-09-27 17:39:54      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:sheet   efi   selection   pen   seo   string   handler   stop   mutable   

 

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组件-打开对话框-选择文件/文件夹获得路径

标签:sheet   efi   selection   pen   seo   string   handler   stop   mutable   

原文地址:http://www.cnblogs.com/v-BigdoG-v/p/7602620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!