Lorenco Gonzaga Lorenco Gonzaga - 3 months ago 8
iOS Question

iOS countdown to show hidden button

I would like to test a code to automatic show a button that initial state is hidden for the user. Then after 40 seconds it appears.

It is a single button placed in navigation bar that performs the code below when its state would change to hidden NO

- (IBAction)done:(id)sender
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}


I would like some help with the countdown code and initial hidden state. The code would be placed in the IBACtion or viewDidLoad...

Thnx and cheers!

Answer

use timer like

-(void) viewDidLoad
{
    [self.btnDone setHidden:true];
    [btnDone addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];

   self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self          selector:@selector(timerFinished) userInfo:nil repeats:NO];
 }
-(void)timerFinished
{
     [self.btnDone setHidden:false];
 }

your method.

 - (void)done
 {
   [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  }
Comments