iPhone OS 5 - 发送到实例的无法识别的选择器



我有一个错误。

UIImage *img = [[UIImage imageNamed:@"bg_message.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(47, 32, 47, 32) resizingMode:UIImageResizingModeStretch];

UIImage *img = [[UIImage imageNamed:@"bg_message.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(47, 32, 47, 32) resizingMode:UIImageResizingModeStretch];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:frame];
[imgView setImage:img];
[imgView setTag:99999999];
[self.view addSubview:imgView];

只需满足操作系统 5、操作系统 6 和 7 通行证。

//This is the error message

* 由于未捕获的异常"NSInvalidArgumentException"而终止应用程序,原因:"-[UIImage 可调整大小图像与CapInsets:ressizeMode:]:无法识别的选择器发送到实例0xd86c2c0"

我不明白。请有人帮助我!谢谢!

-[UIImage resizableImageWithCapInsets:resizingMode:]仅在 iOS 6 上或之后可用。(参考:链接)

如果您在新的 Xcode 中使用此 API 构建应用程序,它不会向您显示任何警告或错误。但是,当您在iOS 5设备中运行该应用程序时,它将引发无法识别的选择器异常。很难抓住这样的错误。因此,最好的测试方法是在iOS 5模拟器/设备上运行。

查找

文档也是一种很好的做法。苹果写得很好。你也可以通过阅读它学到很多东西。

具有 resizeMode 的变体仅在 ios6 中添加。 如果您也想在ios5下运行,则必须检查该方法是否可用。

最新更新