PDA

View Full Version : NSTimer/ BOOLs not working




Programmer
Oct 7, 2009, 06:59 PM
In my application I have a UIImageView and a Button over it. I have a button to start the animation which then Sets an ImageDidAppear BOOL to YES and starts a timer with the same length as the animation. When the timer goes off it sets the ImageDidAppear BOOL to NO. My button only responds if the BOOL = YES. The button stops the animation and also sets the ImageDidAppear BOOL to NO.

The problem is that for some reason the Image shows up in the UIImageView but you can't tap the button to stop the animation or at least when you do hit it , it doesn't work.

Help Please



Kingbombs
Oct 8, 2009, 02:19 AM
put a print command in there to check that you have atleast set up the IBAction to the button, so when you press it make sure the print command appears, then you are able to see where its most likly to be going wrong

Programmer
Oct 8, 2009, 02:02 PM
i've already tried that. and when i take out the timer it works fine but i need the timer to work for my application

dejo
Oct 8, 2009, 03:23 PM
In my application I have a UIImageView and a Button over it. I have a button to start the animation which then Sets an ImageDidAppear BOOL to YES and starts a timer with the same length as the animation. When the timer goes off it sets the ImageDidAppear BOOL to NO. My button only responds if the BOOL = YES. The button stops the animation and also sets the ImageDidAppear BOOL to NO.
Care to include some code snippets? Because I'm a little confused. If the button only responds if the BOOL == YES, but you "have a button to start the animation which then Sets an ImageDidAppear BOOL to YES", how can the BOOL ever get set to YES?

Programmer
Oct 8, 2009, 03:56 PM
- (IBAction)Start {
right1Appaered = YES;

[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector (right1) userInfo:nil repeats:NO];

right1.animationImages = [NSArray arrayWithObjects:

//Image Animation Here

[right1 setAnimationRepeatCount:1];
right1.animationDuration = speed;
[right1 startAnimating];


- (IBAction)right1 {
if (right1Appaered) {
right1Appaered = NO;
Left1Appaered = YES;

[right1 stopAnimating];


}
}

dejo
Oct 8, 2009, 05:43 PM
So, you have one button that when you first tap it, starts the animation and then, while the animation is going, you want to tap the button again to stop the animation, is that correct?

Programmer
Oct 8, 2009, 06:07 PM
i forgot the closed curly bracket.

- (IBAction)Start {
right1Appaered = YES;

[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector (right1) userInfo:nil repeats:NO];

right1.animationImages = [NSArray arrayWithObjects:

//Image Animation Here

[right1 setAnimationRepeatCount:1];
right1.animationDuration = speed;
[right1 startAnimating];

}



- (IBAction)right1 {
if (right1Appaered) {
right1Appaered = NO;
Left1Appaered = YES;

[right1 stopAnimating];

}
}

dejo
Oct 8, 2009, 06:09 PM
But do you have one button or two?

Programmer
Oct 8, 2009, 06:19 PM
two

dejo
Oct 8, 2009, 06:26 PM
And you're sure you have the second button connected to the right1 IBAction correctly in Interface Builder?

Programmer
Oct 8, 2009, 11:38 PM
yes i'm sure like i said everything works if i don't have the timer but i need the timer.

dejo
Oct 8, 2009, 11:48 PM
yes i'm sure like i said everything works if i don't have the timer but i need the timer.
So, if you comment the timer out, then the second button calls the right1 method okay, but if it's included, right1 doesn't get called at all?

Programmer
Oct 9, 2009, 02:31 PM
yes

dejo
Oct 9, 2009, 03:38 PM
What happens if you give your UIImageView and your IBAction different names? Right now they are both right1. That's confusing (to me, at least, probably also to the compiler).

Programmer
Oct 11, 2009, 12:59 PM
sorry it took so long to get back.

I tried what you said and it worked but my question is why does that make the Timer work?

dejo
Oct 11, 2009, 05:38 PM
...but my question is why does that make the Timer work?
Seems the @selector is better able to resolve to the IBAction method
and not the UIImageView, I suppose.