如果我没有来自网址Feed的图片,我想放置默认图片。
if(![[stories objectAtIndex:storyIndex] valueForKey:@"url"]==nil)
{ NSNumber *numberOfKeyInstances = [stories valueForKey:@"key"];
imageArray=[NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"],nil];
int randomNumber_ = rand ()%19;
UIImage *image = [imageArray objectAtIndex:indexPath.row];
cell.imag=image;
}
else{
if (![[[stories objectAtIndex:storyIndex] valueForKey:@"url"] isEqualToString:@""]) {
[cell.imag setImageWithURL:[NSURL URLWithString:[[stories objectAtIndex:storyIndex] objectForKey:@"url"]] placeholderImage:[UIImage imageNamed:@"Alb.png"]];
}
}
这是我的代码,但我得到[UIImage setContentMode:]: unrecognized selector sent to instance 0x7f908c1dcce0'
我怎么解决?
答案 0 :(得分:0)
尝试更改
UIImage *image = [imageArray objectAtIndex:indexPath.row];
到
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:[imageArray objectAtIndex:indexPath.row]]];
答案 1 :(得分:0)
我怀疑cell.imag
是UIImageView
而非UIImage
属性。
所以你需要改变:
cell.imag=image;
到
cell.imag.image = image;
答案 2 :(得分:0)
首先,imageArray
仅使用一个图像进行初始化。所以调用[imageArray objectAtIndex:indexPath.row]
是个问题。你不需要一个图像数组。其次,第一个if
语句中的参数看起来不正确。
另外,正如@ midhun-mp所指出的那样,你应该使用cell.imag.image
。
试试这个:
if([[stories objectAtIndex:storyIndex] valueForKey:@"url"] == nil)
{
cell.imag.image = [UIImage imageNamed:@"1.png"];
}
else if ([[[stories objectAtIndex:storyIndex] valueForKey:@"url"] isEqualToString:@""])
{
cell.imag.image = [UIImage imageNamed:@"1.png"];
}
else
{
//SET YOUR IMAGE HERE
}