在单元格中显示图像时出现以下崩溃。
UIImageView sd_setImageWithURL:placeholderImage:completed:]:无法识别的选择器已发送到实例0x7fbce1521e70“
我遵循了提供的所有指令,但仍然无法获得任何信息,我设置了另一个链接器标志to
-Objc`,但仍然遇到相同的错误。
reference image of cell 我的代码:
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"]];
答案 0 :(得分:0)
您可以检查获得的视图类型,以免发生崩溃。
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.")
}
您需要在“单元格”中为图片视图设置“ tag = 1”,否则您的图片将永远无法填充图片。
答案 1 :(得分:0)
基于您的崩溃日志和下面的代码
UIImageView *img = (UIImageView *)[cell.contentView viewWithTag:1];
变量img
可能为nil或其他视图。仔细检查imageView的标签。
如果一切正确,请检查您的单元格xib(在IBOutlet连接中应该没有任何错误或警告),如果您已使用xib创建了自定义单元格。
答案 2 :(得分:-1)
请尝试将 “其他链接器标志” 设置为 “-ObjC” ,而不是 “ _ Objc”
对我有用。