获取错误[UIImage长度]:无法识别的选择器

时间:2014-05-08 08:56:48

标签: objective-c runtime-error unrecognized-selector

我收到了这个错误

  

2014-05-08 11:36:11.781 LtrRainOptic [1176:c07] * 由于未捕获异常而终止应用程序NSInvalidArgumentException,原因: - [UIImage length]:无法识别的选择器发送到实例0x7af55c0'

 -(void)letterfall
{
   letterView.clipsToBounds = YES;
   image4 = [[UIImageView alloc]initWithFrame:CGRectMake(200, -80, 200, 200)];
   image4.image = [UIImage imageNamed:[sprtL objectAtIndex:0]];
   [letterView addSubview:image4];
   self->falling=[NSTimer scheduledTimerWithTimeInterval:0.015 target:self    selector:@selector(letterPosition) userInfo:nil repeats:YES];
}


-(void)setImagesInArray
{
    if (numLtr == 1)
{
       //if (r == 1) {   [self filltheLetterArray];}
        image4.image = [UIImage imageNamed:[oneletter objectAtIndex:r]];
       r++;
}

}

-(void)filltheLetterArray
{
   fillrequried = [self requiredArray];
   int rand;
    if (numLtr == 1)
   {
       rand = (0 + arc4random()%(1));
      [oneletter replaceObjectAtIndex:rand withObject:[sprtL objectAtIndex:sliderindex]];
      if (rand == 1) {    [oneletter replaceObjectAtIndex:0 withObject:[sprtL objectAtIndex:[self randomImage]]];}
      else           {    [oneletter replaceObjectAtIndex:1 withObject:[sprtL objectAtIndex:[self randomImage]]];}
}
    [self letterfall];
}


-(void)letterPosition
{
    if (numLtr == 1)
    {
        image4.frame = CGRectMake(image4.frame.origin.x, image4.frame.origin.y + 2, image4.frame.size.width, image4.frame.size.height);
    }
    if (image4.frame.origin.y >= 690) 
    {  
        [falling invalidate];
        falling = nil;
        [self filltheLetterArray];
    }
}

1 个答案:

答案 0 :(得分:0)

您的filltheLetterArray方法存在问题,您正在替换oneletter数组中的对象,您将图像(UIImages方法中的randomImage)直接存储到其中,当您分配图像文件名(作为setImagesInArray)但实际上包含image4.image = [UIImage imageNamed:[oneletter objectAtIndex:r]];个对象时,此方法会使应用NSString,此行UIImage崩溃。