在Xcode中创建文件浏览器。 [英] Creating a file browser in Xcode.

查看:126
本文介绍了在Xcode中创建文件浏览器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我是新用户。我正在努力学习如何在这个伟大的操作系统中编程,这种语言对我来说是全新的。我已经知道了C语言,但是我从来没有使用过一些面向对象的语言,请原谅我,如果我说些傻话......

我正在尝试创建一个简单的文件浏览器选择我系统上文件夹中的文件。我会使用Browser对象,但我不知道如何显示其内容。阅读Apple的文档我明白我必须用NSBrowserCell对象填充我的NSBrowser对象等等......但我真的不知道怎么做!

我希望你能帮助我。 ..

解决方案

看看NSOpenPanel课程,我认为这是一个很好的起点:



  //  创建文件打开对话框类。 
NSOpenPanel * openDlg = [NSOpenPanel openPanel];

// 启用对话框中的文件选择。
[openDlg setCanChooseFiles: YES ];

// 不允许多个文件
[openDlg setAllowsMultipleSelection: ];

// 无法选择目录
[openDlg setCanChooseDirectories: NO ];

// 显示对话框。如果按下确定按钮,
// 处理文件。
if ([openDlg runModalForDirectory: nil file: nil ] == NSOKButton)
{
....


Hi guys. I am a new Mac user. I'm trying to learn how to program in this great OS, with this language totally new for me. I already know the C language, but I've never used some object oriented language, then excuse me if I'll say something stupid...
I'm trying to create a simple file browser to select a file in a folder on my system. I would use a Browser object, but I don't know how to display its content. Reading Apple's documentation I understood that I have to fill my NSBrowser object with an NSBrowserCell object and so on... But I don't really know how to do this!
I hope you can help me...

解决方案

Take a look at the NSOpenPanel class, I think that is a good starting point:

// 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 runModalForDirectory:nil file:nil] == NSOKButton )
{
   ....


这篇关于在Xcode中创建文件浏览器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆