Reputation: 469
I need to add a subview to TableViewCell when the button in TableViewCell is clicked it should show another tableview as a subview and height of the tableview should be dynamic according to number of cell.
How can I do this?
Above screenshot is taken from a very popular shopping app and I need to do the same in my project.
Upvotes: 1
Views: 431
Reputation: 351
You can use just one table view with UITableViewStyleGrouped style, and set "Men","Women","Kids & Baby" as TableView sections header, keep an boolean value to determine the result of "numberOfRowsInSection:" of each section and reload tableview.
Upvotes: 1
Reputation: 3526
You need to do some work on your own I can give the directions that'll give you a way from my point of view :-
While designing the cell make its height in storyboard like 200 or so according to your need and add all the elements those you want to see when the cell is expanded.
You'll need two delegate methods first -didSelectItemAtIndexPath and second HeightForRowAtIndexPath at index path.
First You need to make sure the user taps on the button or cell that you want to expand , and to achieve that you need to call didSelectItemAtIndexPath.
Once you get your cell Position, in HeightForRowAtIndexPath check the indexpath is equal to your cell's indexpath,if yes then return the exact height(ie:200) of your cell otherwise return the default(ie:70) height of you cell.
Note : In didSelectItemAtIndexPath you need to call to method to update the current cell
[self.tableView beginUpdates];
[self.tableView endUpdates];
Upvotes: 0
Reputation: 1555
You can easily achieve this using simple UITableView
. For that you need to set all your main categories as your UITableview section and respected sub-categories can be added to respective rowOfSection.
Upvotes: 3
Reputation: 12594
See the below link at github:
https://github.com/OliverLetterer/SLExpandableTableView
This contains the Expandable TableView, which you required. You have to implement SLExpandableTableViewDelegate
and SLExpandableTableViewDatasource
which contains different method, in which you have to provide inner tableview as well.
Hope this helps you.
Upvotes: 0