[UIImageView _isResizable]:无法识别的选择器发送到实例SIGABRT [英] [UIImageView _isResizable]: unrecognized selector sent to instance SIGABRT

查看:216
本文介绍了[UIImageView _isResizable]:无法识别的选择器发送到实例SIGABRT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码试图在一个循环中运行一组简单的图像。我在应用程序中的所有内容都是在我的View Controller的.h文件中声明的一个UIImageView:

I've got this code trying to run a simple set of images in a cycle. All I have in the app is one UIImageView declared in my View Controller's .h file:

@property (strong, nonatomic) IBOutlet UIImageView *imageDisplay;

以下我的.m文件的viewDidLoad方法:

And the following in my .m file's viewDidLoad method:

NSMutableArray *imageView = [[NSMutableArray alloc] init];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim1.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim2.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim3.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim4.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim5.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim6.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim7.png"]]];

imageDisplay.animationImages = imageView;
imageDisplay.animationDuration = 0.25;
imageDisplay.animationRepeatCount = 50;
[imageDisplay startAnimating];

代码似乎在imageDisplay.animationImages行崩溃,好像我创建了UIImageView ,创建它的getter和setter,并构建,直到我取消注释该行为止。如果我取消注释它,它会一直给我错误,直到我删除UIImageView并创建一个新的。

The code seems to be crashing on the "imageDisplay.animationImages" line, as if I create the UIImageView, create its getter and setter, and build, it's fine until I uncomment that line. If I do uncomment it, it keeps giving me the error until I delete the UIImageView and create a new one.

不太确定发生了什么,任何帮助表示赞赏!

Not too sure what's happening, any help appreciated!

推荐答案

animationImages数组必须只包含UIImage对象。您的数组包含UIImageView对象。

animationImages array MUST contain only UIImage objects. Your array contains UIImageView objects.

此外,您的代码不安全 - 如果其中一个资源不存在,应用程序将崩溃(尝试将nil对象添加到可变数组)。这将更加安全:

Also your code is unsafe - if one of the resources will not exist app will crash (trying to add nil object to the mutable array). This will be much safer:

#define kNumberOfImages 7


NSMutableArray *imageView = [[NSMutableArray alloc] init];

for(NSUInteger i = 1; i <= kNumberOfImages; i++) {
    UIImage *anImage = [UIImage imageNamed:[NSString stringWithFormat:@"EyeAnim%d", i]];
    if(anImage) {
        [imageView addObject:anImage];
    }
}

self.imageDisplay.animationImages = imageView;
self.imageDisplay.animationDuration = 0.25;
self.imageDisplay.animationRepeatCount = 50;
[self.imageDisplay startAnimating];

这篇关于[UIImageView _isResizable]:无法识别的选择器发送到实例SIGABRT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆