iPhone - 使用子文件夹

发布于 2024-10-03 17:07:53 字数 996 浏览 0 评论 0原文

我有一个 tableView,其中列出了内容目录,其中包括 jpg、pdf、zip、mp3、mp4、sql、.. 文件甚至文件夹。在下一步中,我将有一个详细视图,它显示所选文件的一些属性,例如文件名、文件大小、文件路径、文件类型。一切都很完美。

但实际上我在详细视图中包含了一个附加选项。

也就是说,

  1. 如果tableView中选择的文件是图像文件,则它会在detailView中打开一个imageView来显示该图像。
  2. 如果所选文件是 mp3,则会打开一个播放器在详细视图中播放该歌曲。
  3. 如果所选文件是视频或 mp4 文件,则会打开一个播放器以在详细视图中播放该视频。
  4. 对于其他文件,它会推送一个警报视图,表明它是未知文件。

(我被困在这里..) 5. 如果所选项目是文件夹,它应该再次打开一个显示文件夹内容的 tableView。

也就是说,它应该在 tableView 中打开子文件和子文件夹,这应该是一个递归函数。请帮助我做到这一点..

我认为我的屏幕截图可能会给出一些想法。

这是我的 tableView,列出了我的目录的内容。

alt text

“SQLTutorial”是上面列表中的一个文件夹

其中 是图像文件的详细视图

alt text

这是视频文件的详细视图

alt text

这是音频文件的详细视图

alt text

请帮助我使用一些示例代码来完成该过程,以在 tableView 中查看文件夹和子文件夹。先感谢您。

I am having a tableView which lists the contents directory which includes jpg, pdf, zip, mp3, mp4, sql,.. files and even folders. In the next step, I am having a detailView which displays some properties of the selected file such as fileName, fileSize, filePath, fileType. Everything works perfect.

But actually I have included an additional option in the detailView.

That is,

  1. If the selected file in the tableView is a image file, it opens an imageView in the detailView to display that image.
  2. If the selected file is a mp3, it opens a player to play the song in the detailView.
  3. If the selected file is a video or mp4 file, it opens a player to play that video in detailView.
  4. For other files, it pushes an alertView regarding that it is an unknown file.

(and I got stuck here..) 5. If the selected item is a folder, it should again open a tableView which displays the contents of the folder.

That is, it should open the subfiles and subfolders in a tableView which should be a recursive function. Please help me to do this..

I think my screen shots may give some ideas.

This is my tableView listing the contents of my directory..

alt text

where "SQLTutorial" is a folder in the above list

This is the detailView of an image file

alt text

This is the detailView of a video file

alt text

This is the detailView of an audio file

alt text

Please help me to complete the process with some sample codes to view the folders and subfolders in a tableView. Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南冥有猫 2024-10-10 17:07:53

最好的办法是将文件夹名称显示为初始列表(您的第一张图像)的一部分,并且选择后,您将使用文件夹的内容创建一个新列表并将其推送到导航控制器。

您可能需要重构您的表视图以拥有一个包含您的“路径”的 ivar 并添加(如果您还没有)导航控制器。

the best thing will be to show the folder name as part of the initial list (your first image) and, when selected, you'll create a new list with the folder's content and push it to a navigation controller.

You'll probably need to refactor your table view to have an ivar which contains your "path" and add, if you don't already have, a navigation controller.

深府石板幽径 2024-10-10 17:07:53

除了 Paul 答案之外,您还可以添加一个“文件夹”ivar 并在选择该行时定义它:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  FolderViewController * detailViewController = [[FolderViewController alloc] initWithNibName:@"yourTableView" bundle:nil];

  UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
  // Set the title of the navigation item for the table view
  detailViewController.folder = cell.textLabel.text;
  detailViewController.navigationItem.title = cell.textLabel.text; 

  // Pass the selected object to the new view controller.
  [controller.navigationController pushViewController:detailViewController animated:YES];
  [detailViewController release];
}

In addition to Paul answer, you can add a 'folder' ivar and define it when the row is selected:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  FolderViewController * detailViewController = [[FolderViewController alloc] initWithNibName:@"yourTableView" bundle:nil];

  UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
  // Set the title of the navigation item for the table view
  detailViewController.folder = cell.textLabel.text;
  detailViewController.navigationItem.title = cell.textLabel.text; 

  // Pass the selected object to the new view controller.
  [controller.navigationController pushViewController:detailViewController animated:YES];
  [detailViewController release];
}
窗影残 2024-10-10 17:07:53

如果文件和文件夹是在视图控制器的 viewDidLoad 中加载的,那么最简单的方法是向视图控制器添加一个属性来指示源文件夹。因此,当用户触摸子文件夹单元格时,您可以初始化新的视图控制器,将属性设置为该子文件夹并将其推送到导航控制器。

If the files and folders are loaded in viewDidLoad of the view controller, so the easiest way is adding a property to your view controller to indicate the source folder. So when the user touches subfolder cell, you can init new view controller, set the property to that subfolder and push it to navigation controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文