Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get UITableViewCell's height after setting height for each UITableViewCell

I set height for each UITableViewCell in

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

I need to get each UITableViewCell's height in

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

because I need to addSubView in different cells.

I've tried to use cell.frame & cell.bounds & cell.contentView.frame, but the height hasn't changed.

like image 473
satgi Avatar asked Dec 15 '22 16:12

satgi


2 Answers

This may be too late, but you can use the delegate method:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGRect cellSize = cell.frame;
}

Hope it helps anyone, Let me know if I missed out something. :)

like image 79
ᴳᴿᴵᴹᴹ Avatar answered Mar 23 '23 01:03

ᴳᴿᴵᴹᴹ


I solved this way:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    // create object
    id myObj = [_arrayEvents objectAtIndex:indexPath.row];

    // create static identifier
    static NSString * myIdentifier = @"Cell";

    // create static UITableViewCell
    static UITableViewCell * cell;

    // create cell with object
    cell = [self buildCell:myIdentifier tableView:tableView obj: myObj];

    return cell.contentView.frame.size.height;

}
like image 42
Wagner Sales Avatar answered Mar 23 '23 00:03

Wagner Sales