Mahesh
Mahesh

Reputation: 524

set height of outer TableViewCell from inner nested UITableViewCell

I'm trying to implement accordion view using UITableView. I want nesting of the view up to 2 levels. (Example : There are multiple Regions under Each Region there will be zero/multiple Locations and under Each Location there will zero/multiple Users). For implementing this scenario I used nested UITableView. i.e Outer TableView (i.e Region TableView) will have its cell as another UITableView (i.e Location TableView) and Each cell of LocationTableView will have another UITableView(i.e TableView Showing users list under each location) as its cell. I have attached the images for more clarification.

In below image Regions are sections of the tableview. (note : not a single row for now in tableview) Outer TableView

After Tapping 2nd section i.e section with name Region I dynamically reload that section and add the cell(i.e the cell that contains the UITableview showing the locations)

Location List Tableview But, it shows the empty space below the location tableview. Instead I want something like this as below :

enter image description here

Again after tapping the 0th section(Location 0) of the inner tableview (i.e tableview containing location list) I dynamically reload that section of tableview and add the cell(i.e the cell that contains the UITableview showing the list of users under that location) Have a look at below image

Innermost tableview i.e userlist tableview

It works perfectly. Now my issue is that I have calculated the height of the outer UITableviewCell in *- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath )indexPath method depending on the number Location within That Region(i.e Cell) and number of Users under each Location under that Particular Region cell. Issue is that I need to hide/show the locations and users list(All the locations and users list is not shown at once)as according to accordionView. So the height of the inner tableView increase/decrease, hence leaving the blank space at the bottom. Also I have created custom UITableViewCell (i.e creating separate nib file for the cell) for each inner cell containing tableview as ContentView and implemented all the UITableView Data Source and Delegate methods in its corresponding .m file. What I want is not to show that empty blank space.

When control goes in the inner tableview cells I can't set the height of the outer UITableView from there.

Hope you understood my problem. Please help me. Thank you!!!

Upvotes: 1

Views: 761

Answers (1)

anoop4real
anoop4real

Reputation: 7718

I had some similar requirements like this, I didnt use the nested tableview as it brought some complexities to me, so I tried playing around with indentation and indexpaths of the tableview to achieve what I wanted. I just did a small sample app with that concept with some dummy data. I have never tried this approach with Custom cells. See if this helps.

I know I am not answering to the exact question that you asked but I am trying to give a different approach which for me looked simpler.

I just modified my base code to match your data

How to create an Accordion with UItableview under a UItableview?

The source can be found here Accordion

Screenshot enter image description here

-anoop

Upvotes: 0

Related Questions