1

cell.imageView is displayed correctly on first loading. After the UITableViewCell move off screen and back on again, suddenly cell.imageView size has changed to fill the height of the cell. Same thing when the cell set to highlighted state. cell.imageView is created in interface builder.

 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSDictionary *dataType = [self.dataTypes objectAtIndex:indexPath.row];
    [cell.imageView setImageWithURL:[NSURL URLWithString:[dataType valueForKey:@"imageURL"]]
                   placeholderImage:nil];

    cell.titleLabel.text = [data valueForKey:@"name"];
    cell.descriptionLabel.text = [data valueForKey:@"info"];

    return cell;
}
TijuanaKez
  • 1,472
  • 3
  • 20
  • 28

2 Answers2

0

try below answer and do needful changes in it

https://stackoverflow.com/a/15331306/1713478

in this answer add

cell.titleLabel.text = [data valueForKey:@"name"];
cell.descriptionLabel.text = [data valueForKey:@"info"];

and just change SimpleTableCell with CustomCell and in imageURL put your image URL

and do other needful changes.

may be your problem will solve.

Community
  • 1
  • 1
Pratik
  • 2,399
  • 17
  • 36
0

Well inspired by Pratik's answer I decided to remove the UIImageView from interface builder and create it on the fly. This works as expected but I'm not sure why it's any different. Possibly something to do with the IB constraints.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSDictionary *data = [self.dataTypes objectAtIndex:indexPath.row];

    UIImageView *thumb = [[UIImageView alloc]initWithFrame:CGRectMake(11, 10, 52, 74)];
    [thumb setImageWithURL:[NSURL URLWithString:[data valueForKey:@"imageURL"]]
                   placeholderImage:nil];
    [cell addSubview:thumb];
    [thumb release];

    cell.titleLabel.text = [data valueForKey:@"name"];
    cell.descriptionLabel.text = [data valueForKey:@"info"];

    return cell;
}
TijuanaKez
  • 1,472
  • 3
  • 20
  • 28