Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tableView cell height... how to customize it?

Tags:

Is it possible to modify height of only one cell in a grouped table view?
I have a table view with 2 sections of 3 and 2 rows... I would change row height of the second row of the second section...

How can I do this?
Thanks!

like image 517
matteodv Avatar asked Sep 17 '10 16:09

matteodv


People also ask

How do you set the height of a Tableview cell?

A few ins-and-outs aside, all you really have to do is: Use Auto Layout for the UI elements inside the table view cells. Set the table view rowHeight to UITableViewAutomaticDimension . Set the estimatedRowHeight or implement the height estimation delegate method.


2 Answers

You can look at this method:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

In your case, the code should look like:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (indexPath.section == 1 && indexPath.row == 1) {
      return SPECIAL_HEIGHT;
   }
   return NORMAL_HEIGHT;
}

You can look for more details about the method here

like image 96
vodkhang Avatar answered Sep 19 '22 06:09

vodkhang


In iOS 8 and above we can use the Dynamic Table View Cell Height.

Using this feature UITableviewCell get its height from its content and We don't need to write heightForRowAtIndexPath

All I have to do in viewDidLoad()

tableView.estimatedRowHeight = 44.0;
tableView.rowHeight = UITableViewAutomaticDimension;

If cell contains uilabel. then apply constraints to uilabel

enter image description here

Make sure you change Label --Lines-- to 0

enter image description here

The cell will grow automatically with content of uilabel:

enter image description here

like image 36
Irfan Avatar answered Sep 19 '22 06:09

Irfan