How to make fixed height cell on uitableview?

Use this delegate method:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 345
}

In your UITableViewController subclass, set self.tableView.rowHeight = 345. Might be a bug with storyboard heights not being translated.


You can set Table View Cell height here.

enter image description here


The reason that you are having this issue is you have probably set your Custom tableview cell's row height to 345 but that is not set as custom while your UITableview's row height is less than 345. So, what you need to do is go to storyboard and select the Table(UITableview) and set its row height to the maximum possible row height.

enter image description here

Let's assume that you are going to have two different kind of row heights. One with 345 and another with 325. As 325<345, you set your tableview's row height to 345.

enter image description here

Now, select the custom tableview cell and make its row height as custom and set that to either 345 or 325. In your case, it will be 345.

enter image description here

It should be good now.

However, more appropriate way when you have different cell size would be to use the delegate method for row height specification.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   if(indexPath.row==0){
      return 345;
   }
   else if(indexPath.row==1){
      return 325;
   }
   else{
      return 300; //a default size if the cell index path is anything other than the 1st or second row.
   }
}