有时候字符串显示“null”我该怎么检查这个错误? if(imageUrl ==(id)[NSNull null]) {
}
答案 0 :(得分:0)
试试这个。
if ([imageUrl isKindOfClass:[NSString class]]) {
[_profileImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"PlaceHoldeImage"]];
}else{
_profileImageView.image=[UIImage imageNamed:@"PlaceHoldeImage"];
}
答案 1 :(得分:0)
NSString *imageUrl= [ProfileArray valueForKey:@"photo"];
if ([imageUrl isKindOfClass:[NSNull class]])
{
_profileImageView.image=[UIImage imageNamed:@"PlaceHoldeImage"];
}
else
{
[_profileImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"PlaceHoldeImage"]];
}
_profileImageView.image=[UIImage imageNamed:@"PlaceHoldeImage"];
答案 2 :(得分:0)
使用此代码。它应该肯定有用。
NSString *imageUrl= [ProfileArray valueForKey:@"photo"];
if ([imageUrl isKindOfClass:[NSNull class]] ) {
_profileImageView.image=[UIImage imageNamed:@"PlaceHoldeImage"];
} else {
[_profileImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"PlaceHoldeImage"]];
}
答案 3 :(得分:0)
试试这段代码。
NSString *imageUrlString= [photoDict valueForKey:@"photo"];
if (imageUrl.length == 0)
{
_profileImageView.image=[UIImage imageNamed:@"PlaceHoldeImage"];
}
else
{
_profileImageView.image=[UIImage imageNamed:imageUrlString];
}