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?

有帮助吗?

解决方案

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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top