1

How to auto resize a cell in tableview based on user input. So that if user inputs a lot of words the cell expands in order so label could expand and all the text could wrap and fit.

Sort of exactly how it is done in iPhone reminder application.

Ekolu
  • 21
  • 2

2 Answers2

0

I think what you need is this -

tableView.estimatedRowHeight = 100
//You can put anything in place of 100.
tableView.rowHeight = UITableViewAutomaticDimension

Hope this helps

Abhishek729
  • 327
  • 5
  • 14
0

Basic implementation is to add constraints on all four side i.e. top, bottom, leading and trailing.

and in viewDidLoad(), setTableViewHeight to UITableViewAutomaticDimension

- (void)viewDidLoad
{
   ...
   ...
   self.tableView.estimatedRowHeight = 50.0;
   self.tableView.rowHeight = UITableViewAutomaticDimension;

  /*To hide separator from empty space at bottom*/
  [[self tableView] setTableFooterView:[UIView new]]; 

}

Follow this nice tutorial, and you will be able to implement the required in no time

Dynamic Height Cell in iOS

gunjot singh
  • 2,578
  • 20
  • 28
  • Thank you, there is just one problem i face after using it. It generates the size of all empty cells based on the user input for one cell instead of generating all cells at said height and adjusting cells where there is greater user input. This leads to all of the empty cells height changing based on the size of user input. Like [this](http://s18.postimg.org/ia3bwi1yx/Screen_Shot_2016_02_23_at_8_38_43_PM.png) and [this](http://s10.postimg.org/63fhmvbp5/Screen_Shot_2016_02_23_at_8_39_12_PM.png). Do you perhaps know how to address this? – Ekolu Feb 23 '16 at 20:08
  • Yes, by default UITableView also shows separator for empty space at bottom. Trick is to set footer view to empty view. I have updated my answer as well. Add below to your viewDidLoad() method [[self tableView] setTableFooterView:[UIView new]]; – gunjot singh Feb 24 '16 at 04:55