-4

I don't see what is wrong with this code as line 4 is getting the "Missing "[" at start of message or expression" and line 6 is getting the error "Expected "].

- (void) subtractTime;
{
     seconds--;
     timerLabel.text[NSString stringWithFormat:@"Time: %i", seconds]

     if (seconds -- 0)
     {
           [timer invalidate];
     }
}

I can't figure out what's wrong and this is really frustrating.

4

1 回答 1

4

You have a couple of syntax issues in your code.

I added:

  1. An equals sign after timerLabel.text, because you're setting the text.
  2. A semicolon after the same line (it's the end of that statement).
  3. A double equals sign for seconds == 0 to compare if seconds equals 0, otherwise the syntax is invalid.

Updated code:

- (void) subtractTime;
{
     seconds--;
     timerLabel.text = [NSString stringWithFormat:@"Time: %i", seconds];

     if (seconds == 0)
     {
           [timer invalidate];
     }
}

Important note:

  1. Where is the seconds variable declared? Make sure this variable is properly managed or else it will always equal 0!
于 2013-07-20T12:30:07.743 回答