Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're using a timer to manage the game, using a perform selector at the same time (to end the game or anything else) kind of defeats the point and makes the management very complex. Choose one route and stick with it.</p> <p>When the timer is running, you can change it's fire date using <code>setFireDate:</code>. So, you could get the current fire date, add your time to it and then set the new fire date:</p> <pre><code>- (void)extendByTime:(NSInteger)seconds { NSDate *newFireDate = [[self.timer fireDate] dateByAddingTimeInterval:seconds]; [self.timer setFireDate:newFireDate]; } </code></pre> <p>Then, your button callbacks are something like:</p> <pre><code>- (void)buttonOnePressed:(id)sender { [self extendByTime:1]; } - (void)buttonFivePressed:(id)sender { [self extendByTime:5]; } </code></pre> <p>Once you've removed the <code>performSelector</code> which calls <code>delay</code> your game end will be defined by <code>MainInt</code> reaching zero.</p> <p>As an aside, don't do this:</p> <pre><code>if (timer == 0) </code></pre> <p>The correct approach is:</p> <pre><code>if (timer == nil) </code></pre> <p>And if the timer is nil, there's no point in trying to invalidate it...</p> <p>Also a good idea to take a look at the Objective-C <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html" rel="nofollow">naming guidelines</a>.</p> <hr> <p>Based on your recent comment, it seems that you actually want the timer to continue counting at a second interval, but to add time only to the number of seconds remaining. That's even easier and doesn't require any change to the timer fire date.</p> <pre><code>- (void)extendByTime:(NSInteger)seconds { MainInt += seconds; seconds.text = [NSString stringWithFormat:@"%i", MainInt]; } </code></pre> <p>And you need to add a check in 'countDownDuration':</p> <pre><code>if (MainInt &lt;= 0) { [timer invalidate]; [self delay]; } </code></pre> <p>To determine when you're done.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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