2 zhu86804396 zhu86804396 于 2015.07.21 11:01 提问

Object c 错误unrecognized selector sent to instance

本人ios编程小白一个,正在学,跟着视频打代码,运行出了这么个错,找了半天也没看出来,各位大大帮忙看下,代码就是tom猫的一个小程序
错误日志
unrecognized selector sent to instance 0x7fbd20627180
2015-07-21 10:52:58.264 Tom[8325:418012] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController drink:]: unrecognized selector sent to instance 0x7fbd20627180'

代码

 #import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tom;

@end

@implementation ViewController

-(void)tomAnimation:(NSString *)img count:(int)count
{
    if([self.tom isAnimating]) return;
    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 0; i < count; i++) {
        NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg",img,i];
//        UIImage *image = [UIImage imageNamed:imageName];
        NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
        UIImage *image = [UIImage imageNamed:path];
        NSLog(@"image is %@ and id is %02d",image,i);
        [arrayM addObject:image];
    }
    [self.tom setAnimationImages:arrayM];

    [self.tom setAnimationDuration:arrayM.count * 0.1];
    [self.tom setAnimationRepeatCount:1];
    //2.开始动画
    [self.tom startAnimating];
    //动画完成之后,再清除动画数组内容


    [self performSelector:@selector(clearTom) withObject:nil afterDelay:self.tom.animationDuration];

}

-(void)clearTom
{
    self.tom.animationImages = nil;
}

- (IBAction)drink
{
    //序列帧动画,所谓序列帧动画,就是让一组图片一张一张的顺序播放
    //1.图片的数组
    [self tomAnimation:@"drink" count:81];
}


@end

3个回答

CSDNXIAON
CSDNXIAON   2015.07.21 11:05

iOS开发之unrecognized selector sent to instance错误
unrecognized selector sent to instance
发生错误unrecognized selector sent to instance的原因
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

u012496940
u012496940   2015.08.04 17:44

方法和类(对象)之间没有对应,也就是对象的类中没有这个方法

ruzhuxiaogu
ruzhuxiaogu   2015.08.05 09:33

将最后一段改为这个试一试

  • (IBAction)drink:(id)sender { //序列帧动画,所谓序列帧动画,就是让一组图片一张一张的顺序播放 //1.图片的数组 [self tomAnimation:@"drink" count:81]; }
Csdn user default icon
上传中...
上传图片
插入图片