UIImageView _isResizable:无法识别的选择器

时间:2012-05-13 19:59:03

标签: iphone objective-c ios uiimageview compiler-errors

我有以下代码在品牌上显示图像但我收到UIImageView错误。 我调整尺寸为800x600的图像以适应iPhone屏幕的大小。

NSURL * url = [NSURL URLWithString:@"http://www.portallzc.com/galerias/galeria_Portal%20de%20Lazaro%20Cardenas/Club%2033/800/p16jklq9uj1f7a1c6tckkjrg1i8015.JPG"];
NSData * urlData = [NSData dataWithContentsOfURL: url];
UIImage * image = [UIImage imageWithData: urlData];
CGRect rect = CGRectMake (0.0f, 40.0f, image.size.width, image.size.height);

image = [[UIImageView alloc] initWithFrame: rect];
[setImage image: image];
  

错误:因未捕获的异常而终止应用   'NSInvalidArgumentException',原因:' - [UIImageView _isResizable]:   无法识别的选择器实例stmt到0x6b8bb70'

2 个答案:

答案 0 :(得分:2)

发生错误是因为您尝试将UIImageView视为UIImage。

myImageView = [[UIImageView alloc] initWithFrame: rect];
[myImageView setImage: image];

如果错误消失,请尝试检查

[self.view addsubview:myImageView];

使您的imageview链接显示屏幕。

如果仍未显示,请尝试检查图像视图的图层。

[self.view bringSubviewToFront:myImageView];

答案 1 :(得分:0)

您的变量命名有错误。 你做的是:

 [imagen setImage: imagen]

你想要做的是:

 [imagen setImage: image];

我在你的问题评论中从我们的谈话中提取了这个。 这不会反映在您的问题中。也许你的问题鳕鱼与你在程序中写的内容不同步。看看你自己的意见,了解我的意思。