Reputation: 560
I have a table view. Now I want to collapse and expand rows by tapping on the section header. In other words, when I tap the header the rows display for that section and taping sub row its display other section How can I do this?
Upvotes: 1
Views: 454
Reputation: 63
You can return your own header view by implementing tableView:viewForHeaderInSection: method (of table view data source). Here you can add tap gesture on header view. Hence when header view is tapped, you can maintain, which header view is tapped in some data structure and should it be expanded or not. Then you can call tableView reloadData method to reload the data and in tableView:numberOfRowsInSection:& tableView:cellForRowAtIndexPath: methods, you can check if this header view is to be expanded, you will prepare the cell for rows for this header view else you will not.
Upvotes: 2