-1

I am getting the following crash while displaying the image in cell. UIImageView sd_setImageWithURL:placeholderImage:completed:]: unrecognized selector sent to instance 0x7fbce1521e70" I followed all the instruction provided but still not able to get anything, I set the other linker flagto-Objc` but still getting the same error.

reference image of cell My Code:

 UIImageView *img = (UIImageView *)[cell.contentView viewWithTag:1];
    NSLog(@"%@",[NSString stringWithFormat:@"%@thumb_%@",kImageUrl,[dict objectForKey:@"student_photo"]]);


    [img sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@thumb_%@",kImageUrl,[dict objectForKey:@"student_photo"]]]
                      placeholderImage:[UIImage imageNamed:@"not_found.png"]];
Sagar Bhut
  • 657
  • 6
  • 28
Rahul
  • 3
  • 5

3 Answers3

0

You can check the type of the view that you get to avoid crash.

UIImageView *img = (UIImageView *)[cell.contentView viewWithTag:1];
if ([img isKindOfClass:[UIImageView class]]) { //it will true if img is kind of UIImageView

    [img sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@thumb_%@",kImageUrl,[dict objectForKey:@"student_photo"]]]
           placeholderImage:[UIImage imageNamed:@"not_found.png"]];
} else {
   NSLog(@"It is not an image view.")
}

You need to set 'tag = 1' to your image view in `cell otherwise your image will never fill with an image.

Mahendra
  • 8,448
  • 3
  • 33
  • 56
0

Based on your crash log and code below

UIImageView *img = (UIImageView *)[cell.contentView viewWithTag:1];

The variable img might be nil or some other view. Double check your imageView's tag.

If everything is correct, check your cell xib(there should not be any error or warning in IBOutlet connection), if you've created a custom cell using xib.

Natarajan
  • 3,241
  • 3
  • 17
  • 34
-1

Please try to set "other linker flag" to "-ObjC" instead of "_Objc"

It worked for me.