1
votes

I have a table-cell which has all default settings. And I put an image on the ImageView on the left, and I put some random text on TextLabel.

and I adjust cell's height using below method.

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

The problem is the left ImageView's frame size is different depend on the cell's height.

See the below image, the 4th cell's height is bigger than others and it's image is slightly right compare to other images.

What causes this and how can I solve this probelm??

alt text

-- added

This is my cellForRowAtIndexPath method.


    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultt reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.text = [self GetSelectionForRowAtIndexPath:indexPath];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"icon_notSelected" ofType:@"png"];
    UIImage *theImage = [UIImage imageWithContentsOfFile:path];
    cell.imageView.image = theImage;

This shows the imageView does not get bigger even if I put more height on the cell.

alt text

3

3 Answers

0
votes
UIImage *image = [UIImage imageNamed:@"your_image.png"];
cell.imageView.image = image;

put this code in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

If will show the image in each cell of the table in same line.

0
votes

You can do it only by Code. No need of IB for this.

0
votes

Give the imageview a fixed frame and then center it vertically in the cell.

Something along these lines:

imageview.frame = CGRectMake(5, floor(cellHeight/2)-20, 40, 40);

Or just use the imageview property of UITableViewCell.