【问题标题】:UIImageView _isResizable: Unrecognized SelectorUIImageView _isResizable:无法识别的选择器
【发布时间】:2012-05-13 19:59:03
【问题描述】:

我有以下代码可以在品牌上显示图像,但出现 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'

【问题讨论】:

  • 什么是[setImage image: image]; ?你的对象叫 setImage 吗?好坏的名字
  • 对不起是:image = [[UIImageView alloc] initWithFrame: rect]; [图像集图像图像:图像];
  • 为什么要设置 imageView 的图像等于 imageView 本身?
  • 不过,该签名不是有效的语法。
  • 我有:NSURL * url = [NSURL URLWithString:@"portallzc.com/galerias/galeria_Portal%20de%20Lazaro%20Cardenas/…; NSData * urlData = [NSData dataWithContentsOfURL: url]; UIImage * image = [UIImage imageWithData: urlData]; CGRect rect = CGRectMake (0.0f, 40.0f, image.size.width, image.size.height); imagen = [[UIImageView alloc] initWithFrame: rect]; [imagen setImage: imagen];

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


【解决方案1】:

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

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

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

[self.view addsubview:myImageView];

使您的 imageview 链接到显示屏幕。

如果仍然没有出现,请尝试检查图像视图的图层。

[self.view bringSubviewToFront:myImageView];

【讨论】:

    【解决方案2】:

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

     [imagen setImage: imagen]
    

    你想做的是:

     [imagen setImage: image];
    

    我从我们在您问题的 cmets 中的对话中提取了这一点。 这没有反映在您的问题中。也许您的问题代码与您在程序中编写的内容不同步。看看你自己的 cmets 就明白我的意思了。

    【讨论】:

    • 我已经有了你所说的但没有给我看图片?措施会是什么? imagen = [[UIImageView alloc] initWithFrame: rect]; [图像集图像:图像];
    • @MovileMX,您是否尝试过记录图像以查看它是否不为零?
    猜你喜欢
    • 2012-03-25
    • 2013-07-16
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多