Gimme the 411
Gimme the 411

Reputation: 1044

Is it OK to have many nested UITableViews or is there a better way to achieve this?

I'd like to make a menu layout like this:

enter image description here

I've considered doing it with this hierarchy:

UITableView (Whole menu)
-UITableViewCell (Each Category, for example Category 3)
 -UITableView (Each Category, for example Category 3)
  -UITableViewCell (Category items, for example item 2)
   -UITableView (Category items, for example item 2)
    -UITableViewCell (item sub-rows, for example item 2(#1))

As shown in this diagram:

table/cell layout diagram

Some things that are important:

  1. If it's possible, I'd like to disable to ability to click on an item sub-row. If someone clicks on the row of item 2(#1) I don't want it to highlight and select the whole row. I only want something to happen when someone pressed the [-] button on that row. Is this possible with UITableViewCells?
  2. I need the ability to dynamically add sub-rows for each item at runtime. When a user presses the [+] button for an item, it should add 1 item sub-row below it (which I assume would make sense as a UITableViewCell).

Does this many nested UITableViews and UITableViewCells make sense? Is this the most appropriate way to achieve a layout like this? And does my proposed hierarchy seem accurate for this design?

EDIT:

If I use just 1 UITableView and 3 types of cell, will I be able to achieve the functionality I need? Can I add rows, then collapse the category, then expand the category again (and the added rows will still be there), and then remove cells?

Upvotes: 2

Views: 980

Answers (2)

Jayraj Vala
Jayraj Vala

Reputation: 224

No need to use nested TableViews if you don't need scrollable content, instead use sections and make them expandable and collapsable as per your need.

Upvotes: 0

Anton Filimonov
Anton Filimonov

Reputation: 1675

Why do we use UITableView? IMHO mostly for these reasons:

  1. It is scrollable (which you don't need for nested ones)
  2. Using table view it is easy to show dynamic list of views with the same styles (for which one table view is pretty much enough)
  3. It allows to use less resources by reusing cells (which will help much less in case of nested table views than if you use another kind of cells in the same table view as @Tj3n offered)

So according to these points I'd say it's better to use just one UITableView for your case. (Can't say, your way not OK because you actually can make it work)

Upvotes: 1

Related Questions