I got this error

2014-05-08 11:36:11.781 LtrRainOptic[1176:c07] * Terminating app due to uncaught exception NSInvalidArgumentException, reason: -[UIImage length]: unrecognized selector sent to instance 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];
    }
}
有帮助吗?

解决方案

There's problem in your filltheLetterArray method, you're replacing objects in oneletter array, you're storing images (UIImages from randomImage method)directly into it, and this method crashing the app, setImagesInArray, this line image4.image = [UIImage imageNamed:[oneletter objectAtIndex:r]]; as you're assigning image file name (as NSString) but actually its containing UIImage objects.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top