gpt4 book ai didi

objective-c - 打开文件对话框

转载 作者:太空狗 更新时间:2023-10-30 03:27:06 24 4
gpt4 key购买 nike

我正在学习 Objective-C 并尝试开发一个简单的 zipper 应用程序,但我现在停止了,当我需要在我的对话框中插入一个按钮时,这个按钮会打开一个打开文件对话框,它将选择一个文件进行压缩,但我从未使用过打开文件对话框,那么如何打开它并将用户选择的文件存储在 char* 中?谢谢。

请记住,我使用的是 GNUstep(Linux)。

最佳答案

感谢@Vlad the Impala 我正在为使用 OS X v10.6+ 的人更新您的答案

// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];

// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];

// Multiple files not allowed
[openDlg setAllowsMultipleSelection:NO];

// Can't select a directory
[openDlg setCanChooseDirectories:NO];

// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModal] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* urls = [openDlg URLs];

// Loop through all the files and process them.
for(int i = 0; i < [urls count]; i++ )
{
NSString* url = [urls objectAtIndex:i];
NSLog(@"Url: %@", url);
}
}

关于objective-c - 打开文件对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1640419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com