Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get a function to pause until the NSTimer selector is finished?
    primarykey
    data
    text
    <p>I have an NSTimer in another function but I want to be able to wait for the NSTimer to become invalidated before continuing on with the code is there a way to do this?</p> <pre><code> - (IBAction)addLifePoints:(UIButton *)sender { [[ARCHDuelCalculator sharedARCHDuelCalculator] setLifePointDelta:[NSNumber numberWithInt: [self.hiddenTextField.text intValue]]]; [[ARCHDuelCalculator sharedARCHDuelCalculator] setAddOrSubstract: YES]; [[ARCHDuelCalculator sharedARCHDuelCalculator] applyingDeltaToLifePointsByDelta]; // This will animate the life points animationTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(animateLifePoints) userInfo:nil repeats:YES]; // This is where we bring it back to the view controller self.duelistOneLifePoints.text = [[ARCHDuelCalculator sharedARCHDuelCalculator].duelistOneLifePoints stringValue]; self.duelistTwoLifePoints.text = [[ARCHDuelCalculator sharedARCHDuelCalculator].duelistTwoLifePoints stringValue]; self.hiddenTextField.text = @""; [self syncTextField: self.hiddenTextField]; [self.hiddenTextField resignFirstResponder]; } - (void) animateLifePoints { NSNumber *sections = [[ARCHDuelCalculator sharedARCHDuelCalculator] getLifePointSections]; for(int timer = 0; timer &lt; 100; ++timer) { self.duelistOneLifePoints.text = [[[ARCHUtilities sharedARCHUtilities] subtractTwoNSNumbersByDataType:@"int" firstNumber:[NSNumber numberWithInt: [self.duelistOneLifePoints.text intValue]] secondNumber:sections] stringValue]; if ((timer % 14) == 0) { [self playLifePointSound:@"mainLifePointSound" typeOfFile:@"mp3"]; } } [animationTimer invalidate]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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