Reputation: 71
I have an application that I'm working on that requires the user to browse through stored files within the app's root folder. I am wanting to use a navigation style similar to the settings tool on iOS where you have a list of items, then you click on one, it brings up another list of items with a back button, etc, until it hits the end.
I can't seem to find any examples on how to do this where its recursive.
The navigation should look something like this:
- Learning Swift
- Monday
- How to read files
- material1.pdf
- material2.pdf
- Tuesday
- Using UI Controllers
- material3.pdf
- PHP
- Thursday
- material4.csv
- material5.pdf
- Ruby
- Saturday
- Using Models
- Help Materials
- material6.pdf
- Code Samples
- config.rb
- controller.rb
- material7.pdf
etc
There is no set folder structure so I would need this to be able to be generated dynamically. I am going to be reading the folder structure from the app storage directory on the device each time the user accesses this portion of the app.
Thanks
Upvotes: 0
Views: 272
Reputation: 535557
You do it just like the Settings app, the Files app, the Phone app, and any other app that has push navigation down into a hierarchy.
You have a UINavigationController whose root view controller displays a table view where you list the folders at the root of the navigation. The user picks one by tapping, and you create another view controller that displays a table view where you list the files/ folders in that folder, and push it onto the navigation controller — and so on, recursively. So sideways is always one level deeper (or, using the Back button, shallower). You don't create and populate the next level deep until the user has tapped, at which point you just pick up the required info (what's in this folder) and display it.
Another option would be to present the entire hierarchy of the folder in question as an outline, that is, a single scrolling table view with indentations. In iOS 14, you can even have an outline that works like list view in Finder, with folders that the user can twiddle open right there in the list.
Upvotes: 1