On click of table cell it will dynamically increase the label height and if user click on another cell previsoly opened cell will collapse and expand selected cell.I was try hard for this bt label text is not working well.I want increase the height of cell.exa- click on question cell it will expand the answer
Asked
Active
Viewed 1,144 times
1
-
1possible duplicate of [Expanding and Collapsing table view cells in ios](http://stackoverflow.com/questions/19855832/expanding-and-collapsing-table-view-cells-in-ios) – Daniel Dec 01 '14 at 15:49
-
There are large numbers of questions exactly the same as this on StackOverflow. Please do a search. – Robotic Cat Dec 01 '14 at 15:49
-
possible duplicate of [UITableViewCell expand on click](http://stackoverflow.com/questions/4635338/uitableviewcell-expand-on-click) – Robotic Cat Dec 01 '14 at 15:49
-
Also: http://stackoverflow.com/q/19112153/558933 – Robotic Cat Dec 01 '14 at 15:50
1 Answers
1
Connect UITableViewCell to the code behind, have a state for that cell and on didSelectRowAtIndexPath change cell height to whatever value you want. Regarding of the state of the cell ( you can do this by checking its height as well ) shrink or expand the cell.
You can do this by adding another cell below "question" cell and make it visible or hidden on click as well.

Miknash
- 7,888
- 3
- 34
- 46
-
I had tried the solution of adding new row on click of cell using indexset but now problem is how to remove that if I click on another cell then previous remains open and it will expand selected row.previous cell should be collaps.from here I have problem.I tried this link:http://cocoanetics.com/2011/03/expandingcollapsing-tableview-sections.this is the first time I m going to create this tableview so I have no idea for this. – Dhaval Umraliya Dec 01 '14 at 16:09
-
So, you want to shrink every other cell but to show selected? you can call [self.tableView reloadData] to redraw the table and then(while redrawing) to show selected one. You can do this in didSelectRowAtIndexPath(I haven't tested it ) by calling reloadData first and then changing the height of particular cell. Btw. your link contains ".this" and therefore is not working. – Miknash Dec 01 '14 at 16:16
-
Thanks for reply..please check this link - http://www.cocoanetics.com/2011/03/expandingcollapsing-tableview-sections/ – Dhaval Umraliya Dec 01 '14 at 16:32
-
1I checked it, and I think it's unnecessary compllication with NSMutableIndexSets... You can do this like following: Even cells could be questions (divisable by 2). For selected cell you can save IndexPath. Uneven cells are for answers. You just have to keep every test case in mind since UITableView reuses cells. So, you can reload data on did select row at index path, save index path and in cellForRowAtIndexPath you can check should you show particular cell or not. Also, you can manage reused cells here so you don't have any glitch – Miknash Dec 01 '14 at 17:19
-
Its Done now.I just put the button with clear color.on click of button I set the index path in indexset and check the selected index and according to index table will reload.and in the didselectrow method I just reload my table view.done – Dhaval Umraliya Dec 02 '14 at 13:22
-
1I think its similar to something I proposed to you. If you find any of my comments useful please upvote or mark my answer as correct :) Thnx and good luck :) – Miknash Dec 02 '14 at 13:28