Image "moves" when varying heightForRowAtIndexPath in UITableViewCell.

Posted by Kalle on Stack Overflow See other posts from Stack Overflow or by Kalle
Published on 2010-03-11T16:12:33Z Indexed on 2010/03/11 21:49 UTC
Read the original article Hit count: 448

I have a table view with varying height, as defined in the heightForRowAtIndexPath. For some very odd reason, the image is "indented" to the right based on the height; if the height is low enough, the image is stuck to the left side of the cell, but as the height increases, the image for said cell is shifted rightward compared to other rows.

The result of this is a very poor looking list, with images floppily laid out in a zig-zag pattern depending on the height of each individual row.

The problem is revealed by this simple example:

- (CGFloat)tableView:(UITableView *)tableView 
  heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return (indexPath.row+1) * 50;
}

Each cell is set up (simplified) as a "Subtitle" style cell with:

// ...
cell.textLabel.text = @"foo";
cell.detailTextLabel.text = @"bar";
cell.imageView.backgroundColor = [UIColor redColor]; // for debugging; i have images with transparent bg
cell.imageView.image = anImageThatIs55x50pixelsBig;
return cell;

Any ideas? My head bleeds from the wall-love-affair.

Edit: uploaded a screen which displays this. The "image" is just a screenshot of a tiny area of the screen which makes it look a little weird, but you get the picture I'm sure: http://img28.imageshack.us/img28/549/screenshot20100311at172.png

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk-3.0