質問

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