jeudi 14 mai 2015

else if statement doesnt seem to be executed

I have an if statement which checks if a draggable imageView intersects with another imageView which keeps count of the amount of items dragged to it and changes an image. Also have else if statement to see if 2 imageViews were intersected with the counter imageView. The first if statement works fine bun when i go to drag another one on to it nothing happens. The image stays the same and doesnt change. I tried to do it this way but it doesnt seem to work. Anyone know why and if there is a better way to do it?

My code:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    for (UIImageView *letter in letterA)
    {
        if (CGRectIntersectsRect(letter.frame ,answerA.frame))
        {
            UIImage *Pic1 = [UIImage imageNamed:@"number1"];
            [correctCounterA setImage:Pic1];
            letter.userInteractionEnabled=NO;
            letter.hidden=YES;

        }
        else if(CGRectIntersectsRect(letter.frame ,answerA.frame) && CGRectIntersectsRect(letter.frame, answerA.frame))
        {
            UIImage *Pic2 = [UIImage imageNamed:@"number2"];
            [correctCounterA setImage:Pic2];
            letter.userInteractionEnabled=NO;
            letter.hidden=YES;
        }
    }

}

Aucun commentaire:

Enregistrer un commentaire