UITableViewCell imageView not showing

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 do not see the image in the cell. What am I doing wrong?

+6
source share
4 answers

1) Set image with url is not iOS method. This is something common, and it can be a problem. But until you publish it, it will not help.

2) I think cell.imageView is ignoring "setFrame". I cannot get this to work in any of my table cells using an image. It seems that the default image is equal to the width by default.

3) Usually you set the image using cell.imageView.image = your_Image. ImageView is READONLY and probably the ImageView frame is closed.

4) I think you will need to create your own cell.

+3
source

I have the same problem with SDImageCache. My solution is to place a placeholder image with the required frame size.

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

Using a placeholder method will fix it.

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

you need 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; } 
+2
source

Source: https://habr.com/ru/post/916396/


All Articles