Domanda

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?

È stato utile?

Soluzione

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;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top