Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a button appear and disappear throughout a timer
    text
    copied!<p>I have this app which has a timer in it and I want to be able to display a button at random points in that timer. Sort Of like a game setting where you have to get the button to get more time before it disappears. I already have some code , but the problem is that the timer that i already have is being messed up ( i can tell because it is linked to a label. It messed up because it goes down by 2 instead of 1 and this only happens when i have the code to make the button appear and disappear with the timer.</p> <p>Here is the code to my timer that is being messed up:</p> <pre><code>-(IBAction)Ready:(id)sender { [self performSelector:@selector(TimerDelay) withObject:nil afterDelay:1.0]; [self performSelector:@selector(randomTimer) withObject:nil afterDelay:0.5]; } -(void)TimerDelay { MainInt = 36; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownDuration) userInfo:nil repeats:YES]; } </code></pre> <p>Here is the code to the button:</p> <pre><code> -(IBAction)Ready:(id)sender { //the same ready action as above [self performSelector:@selector(TimerDelay) withObject:nil afterDelay:1.0]; [self performSelector:@selector(randomTimer) withObject:nil afterDelay:0.5]; } -(void)TimerDelay { MainInt = 36; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownDuration) userInfo:nil repeats:YES]; } - (void)randomTimer { NSInteger randomTime = arc4random_uniform(0); //Some number between 0 and 9 timer = [NSTimer scheduledTimerWithTimeInterval:randomTime target:self selector:@selector(showButton) userInfo:nil repeats:NO]; } - (void)showButton { if(self.plus5.hidden == YES) { self.plus5.hidden = NO; } else { self.plus5.hidden = YES; } [self TimerDelay]; //Call random timer function again to run this method at a future random time } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload