UITableView Tree Structure Implementation

I am trying to configure a UITableView to display threaded nested elements. I use Core Data and NSFetchedResultsController but don’t know what my approach should be. I want to display the following information:

  • Item No. 1
    • Item No. 1.1
    • Item # 1.2
    • show all
  • Item number 2
    • Item No. 2.1
    • Item # 2.2
    • show all

In the section above, each subsection has a "Show All" button, which, when clicked, will be replaced by additional sub-elements (each mark above is a cell with one tabular view). Has anyone done something like this and had any hints of approaches? Thanks.

+2
source share
2 answers

I would not try to squeeze the NSFetchedResultsController into a mode for which it was not created. FRC does not have built-in support for nested tables, and I think it will take more work to crack it for a nested table than just writing your own table view controller to solve this problem. This is doubly true if your table will display objects from two or more objects.

In addition, I would caution against using nested tables on a portable mobile device. Only about 11 lines of standard size will be displayed on the iPhone screen. So, given your example above, you will only see two or three node headers at any time. Worse, if you have a node with more than 11 leaves, you will not see anything but the leaves screen, and the hierarchical nature of the table will be masked.

In most cases, a hierarchy of table views, each of which is displayed on a separate level, is almost always the best design.

+4
source

You can use section headers to split your list, with the title being the name of the element. All items will be available, and you can simply scroll through them all at once. Since you only need one level of indentation, this may work for you.

I saw a rather efficient use of subitems in an application called GoTasks (free download from the app store), which shows subtasks as a few indentation (although it does not crash), I think it is quite effective, even without a screen on my iPhone. Unfortunately, my iPhone development experience is not enough to tell you how to do this.

+1
source

Source: https://habr.com/ru/post/1399758/


All Articles