NSArray [UIImage setContentMode:]
NSArray [UIImage setContentMode:]
如果我没有来自 url 提要的图像,我想放置默认图像。
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'
我该如何解决?
尝试改变
UIImage *image = [imageArray objectAtIndex:indexPath.row];
至
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:[imageArray objectAtIndex:indexPath.row]]];
我怀疑 cell.imag
是 UIImageView
而不是 UIImage
属性。
所以你需要改变:
cell.imag=image;
到
cell.imag.image = image;
首先,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
}
如果我没有来自 url 提要的图像,我想放置默认图像。
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'
我该如何解决?
尝试改变
UIImage *image = [imageArray objectAtIndex:indexPath.row];
至
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:[imageArray objectAtIndex:indexPath.row]]];
我怀疑 cell.imag
是 UIImageView
而不是 UIImage
属性。
所以你需要改变:
cell.imag=image;
到
cell.imag.image = image;
首先,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
}