UITableViewCell imageView not showing

14,323

Solution 1

1) Set Image with URL is not an iOS method. It's something custom and that may be the problem. But until you publish it can't help there.

2) I think cell.imageView will ignore "setFrame". I can't get that to work in any of my table cells using an image. It always seems to default to width of the image.

3) Typically you set the image using cell.imageView.image = your_Image. The ImageView is READONLY and probably the ImageView frame is private.

4) I think you are going to need to create a custom cell of your own.

Solution 2

I got the same problem with SDImageCache as well. My solution is to put a placeholder image with the frame size you want.

 UIImage *placeholder = [UIImage imageNamed:@"some_image.png"];
 [cell.imageView setImage:placeholder];
 [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];

Solution 3

Usage of a method with placeholder will fix it.

[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]];

Solution 4

you need to return cell at the end of the method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = @"FriendsCell";

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row];

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    [cell.imageView  setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)];
    [cell.textLabel setText:fd.name_];
    return cell;
}
Share:
14,323
adit
Author by

adit

Updated on June 21, 2022

Comments

  • adit
    adit almost 2 years

    So I had the following code:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        NSString *CellIdentifier = @"FriendsCell";
    
        FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row];
    
        UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
    
        [cell.imageView  setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];
        [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)];
        [cell.textLabel setText:fd.name_];
    
        return cell;
    }
    

    However, I am not seeing the imageView in the cell. What am I doing wrong?