使用文件弹窗进行文件选择

来源:互联网 发布:发票打印软件 编辑:程序博客网 时间:2024/06/03 17:12

NSOpenPanel *openDlg = [NSOpenPanelopenPanel];

[openDlg setCanChooseFiles:YES];

[openDlg setCanChooseDirectories:YES];

[openDlg setPrompt:@"Select"];

if([openDlgrunModalForDirectory:@"/AppleInternal/Applications"file:@"myAppName.app"] ==NSOKButton)

{

NSArray *files = [openDlgfilenames];

for(int i =0; i < [filescount]; i++){

NSString *fileName = [filesobjectAtIndex:i];

NSLog(@"Select File Name : %@",fileName);

[pathControl setURL:[NSURLfileURLWithPath:fileName]]; //NSPathControl *pathControl

}

}



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

NSOpenPanel *op = [NSOpenPanelopenPanel];

[op setCanChooseFiles:YES];

[op setCanChooseDirectories:YES];

[op beginSheetForDirectory: [[pathSelectURL]path]

 file: nil

types:nil

modalForWindow: [selfwindow]

modalDelegate:self

didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)

 contextInfo: nil

];


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- (void) openPanelDidEnd:(NSOpenPanel *)op

  returnCode:(int)returnCode

contextInfo:(void *)ci

{

if (returnCode ==NSOKButton) {

//NSString* path = [op filename];

NSArray *files = [opfilenames];

for(int i =0; i < [files count]; i++){

NSString *fileName = [filesobjectAtIndex:i];

NSLog(@"Selsct File Name : %@",fileName);

[pathSelectsetURL:[NSURLfileURLWithPath:fileName]];

}

}

}


原创粉丝点击