-1

I have four UIView which is placed on UITableViewCell just like each cell contain one view. And I want to expand the TableViewCell dynamically when click on perticular cell and also adjust following cell. How it can be done?

Pritam Salunkhe
  • 87
  • 1
  • 11

2 Answers2

1

You'll need to call tableView.beginUpdates(), then call tableView.reloadRowsAtIndexPaths(:withRowAnimation:) on the row index you want to change, and tableView.endUpdates().

You'll also need to implement tableView(:heightForRowAtIndexPath:). That should return the 'standard' height for most rows (44.0 by default), and then a larger value for the expanded row.

iAnurag
  • 9,286
  • 3
  • 31
  • 48
Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
0

Some sample code:

            @implementation ViewController {

                NSIndexPath *indexPathToExpand;
            }

            -(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
                 if(indexPath == indexPathToExpand)
                     return expandedHeight;
                 else 
                     return defaultHeight;
            }

           -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
                  indexPathToExpand = indexPath;
                  [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            }

            @end
Vinod Vishwanath
  • 5,821
  • 2
  • 26
  • 40