NSArray [UIImage setContentMode:]

时间:2015-02-09 11:18:48

标签: ios objective-c uiimage

如果我没有来自网址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'

我怎么解决?

3 个答案:

答案 0 :(得分:0)

尝试更改

UIImage *image = [imageArray objectAtIndex:indexPath.row];

UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:[imageArray objectAtIndex:indexPath.row]]];

答案 1 :(得分:0)

我怀疑cell.imagUIImageView而非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
}