2

I want to expand and collapse the first row on button click. Button is in navigation bar. Can anybody help me in this. Through Code.

Syed Uzair Ahmed
  • 144
  • 1
  • 14

1 Answers1

1

When You click on the button,just check the state on 1st row of a table if it is collapsed then reload 1 row using reloadRowAtIndexpath method and change the size of the cell in size for row at indexpath.Same Procedure while collapsing.

For Expand and Collapse :-

-(IBAction) aButtonTapped:(id)sender {

[[self tableView] beginUpdates];
[[self tableView] reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem: 0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
[[self tableView] endUpdates]; }

Change the height in heightForRowAtIndexpath and apply check to see if the row is already expanded or not

Diksha
  • 439
  • 7
  • 22
  • you can take reference from @Vijay Blog,check it out and let me know if its done or not – Diksha Jul 18 '16 at 07:28
  • I saw that. but my scenario is change. Just tell me the code i will use for button click. and how i will access that cell in button click method. – Syed Uzair Ahmed Jul 18 '16 at 09:38
  • @ MAfioso check out this thread:-http://stackoverflow.com/questions/29565758/uitableview-how-to-change-cell-height-dynamically-when-a-button-is-clicked-in-i – Diksha Jul 18 '16 at 09:47
  • Can you guide me ? It will be hidden on view did load. and when i click button it expand. guide me through code. I m totally new to it. – Syed Uzair Ahmed Jul 18 '16 at 10:03
  • 1
    You Can take a bool variable which will check if the row is expanded or collapsed and then when you click on button reload the cell and then in HeightForRowAtIndexpath check the value for bool variable and accordingly expand and collapse the cell.You have to Code Yourself for this,it will be good for you – Diksha Jul 18 '16 at 10:07