Table Cell not displaying correctly

308 views Asked by At

I've designed a custom table cell as follows: enter image description here

However, it is rendering as follows:

enter image description here

as you see, the second label is going in the next cell. Any idea how can I solve this issue and make the cell appear as I designed it?

1

There are 1 answers

0
Puneet Sharma On BEST ANSWER

You need to implement UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

This method:

Asks the delegate for the height to use for a row in a specified location.

Give a minimum height for each row here. Also if different row have different height according to the content, you have to calculate the height according to the content in that case. Something like this:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *stringText=[array objectAtIndex: indexPath.row];
    CGSize size = [stringText sizeWithFont:[UIFont fontWithName: "yourFont" size: fontSize] constrainedToSize:maxCGSize];
    return labelSize.height + padding;
}