Alec
Alec

Reputation: 177

Have access to UITableViewCell from heightForRow

I have the following code:

- (CGFloat)tableView:(UITableView *)_tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    return cell.imageView.frame.size.height + 40;

}

What I want to do is be able to access the cell's properties somehow. I want the cell's height to be equal to the height of the image in the cell's image view. I don't think this is working.

Upvotes: 0

Views: 1308

Answers (1)

jscs
jscs

Reputation: 64002

Don't try to access the cell. Your table's data source or some other object besides your cell should be managing that image. Ask that object for the image and take its size.

Treating your cell as a data container is tangling up your model, view, and controller layers and is likely to make changes more difficult down the line.

Upvotes: 2

Related Questions