heightForRowAtIndexPath and customize tableviewcell height

123 Views Asked by At

I want to know if I have customized my own tableviewcell with a specified height and this value is not the same as I used in heightForRowAtIndexPath. Which height will be used for the cell. Since I have multiple customized cells in one tableview, it will be difficult for me to distinguish each type of them in the heightForRowAtIndexPath function. I just want to know in this case, can I just use the cell height I defined for each type of cell?

3

There are 3 best solutions below

0
On BEST ANSWER

My found is that before iOS8, you have to specify the row height in heightForRowAtIndexPath. Until iOS8, Apple provides autolayout and resize of cell, e.g. adding constraints. Not sure if this is the only way to control the cell row height or not.

0
On

According to the UITableViewDelegate protocol reference,

The method allows the delegate to specify rows with varying heights. If this method is implemented, the value it returns overrides the value specified for the rowHeight property of UITableView for the given row.

0
On

You can implement this method of the UITableViewDelegate

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

    //The height you desire to have for the row at *indexPath*

    }