hodgesmr
hodgesmr

Reputation: 2785

Reusing UITableViewCell moves subview frame

I'm subclassing UITableViewCell. In the xib for my custom cell, I have an UIImageView that has a frame of (0, 0, 57, 57). It has autolayout constraints set to top, left, width, and height.

When the table view is first rendered, all the cells look fine. But when I scroll around, (and thus reusing the celles) the frame for the UIImageView shifts to (15, 0, 57, 57). None of the other subviews seem to be affected.

enter image description here

The UITableViewDataSource:

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    Content* content = [[[ContentManager sharedContentManager] allContent] objectAtIndex:indexPath.row];
    ContnetCell* cell = [tableView dequeueReusableCellWithIdentifier:kCellReuseIdentifier forIndexPath:indexPath];
    [cell loadWithContent:content];
    return cell;
}

The Cell:

{
    [super prepareForReuse];
    self.imageView.image = nil;
}

-(void)loadWithContent:(Content*)content
{
    self.imageView.image = content.contentImage;
}

Upvotes: 1

Views: 474

Answers (1)

eunoia
eunoia

Reputation: 246

It's a custom cell right? If you use the same property names for your custom images or labels as those found in a default cell (i.e, imageView, textLabel or detailTextLabel), strange things can happen. Try renaming imageView to something else and see if that fixes it.

Upvotes: 4

Related Questions