2

私は自分のプログラムを以下のように実行しました。

- (IBAction) toolbarOption:(UIBarButtonItem *)sender
{
    switch ([sender tag]) {

        case 0:

            [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
        break;

        case 1:

            for (int i=0; i< [array count]; i++)
            {
            label02.hidden = YES;
            label03.hidden = YES;
            label01.text = [array objectAtIndex:i];

            order.text = [NSString stringWithFormat:@"%i of %i", i+1,[array count]];

            NSDictionary *pronunciation = [[SingletonHandle getHandle] getPronunciationPlist];

            label02.text = [pronunciation objectForKey:label01.text]; 
            label03.textColor = [UIColor redColor];
            label03.text = [meaning objectForKey:label01.text];

            [self performSelector:@selector(showButton:) withObject:nil afterDelay:2.0];

            NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:nil selector:@selector(showButton:) userInfo:pronunciation repeats:NO];
            [timer fire];                
            }

        break;

        default:
        break;
}

-(IBAction)showButton:(id)sender
{
    label02.hidden = NO;
    label03.hidden = NO;
    nextButton.hidden = NO;
    previousButton.hidden = NO;
    order.hidden = NO;
}
...

label.text時間の遅れとともに変化するintとして表示したいのですが、機能しません。それは私に最後を示していlabel.textます。label.textを使って時間遅れでそれぞれを見たいですNSTimer。前もって感謝します。

4

2 に答える 2

1

NSTimerは次のように使用できます

theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f 
        target:self 
        selector:@selector(updateTimer:) 
        userInfo:nil 
        repeats:YES];`

そして、あなたはfuncであなたのラベルを更新することができます

- (void)updateTimer:(NSTimer *)theTimer {
    //static int countTime = 0; 
    countTime += 1;
    _timeOver=_timeOver-1;
    NSString *s = [[NSString alloc] initWithFormat:@"Time left: %d", (_timeOver)];
    self._myTimeCounterLabel.text = s;
    [s release];
    if (_timeOver==0) {
        [self checkIfGameOver];
    }
}
于 2012-11-20T08:08:49.687 に答える
0

これを試して、

NSTimer *aTimer = [NSTimer timerWithTimeInterval:(3.0) target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
    NSRunLoop *runner = [NSRunLoop currentRunLoop];
    [runner addTimer:aTimer forMode: NSDefaultRunLoopMode];

タイマーアクション

- (void)updateTimer:(NSTimer *)theTimer {
    //static int countTime = 0; 
    countTime += 1;
    _timeOver=_timeOver-1;
    NSString *s = [[NSString alloc] initWithFormat:@"Time left: %d", (_timeOver)];
    self._myTimeCounterLabel.text = s;
    [s release];
    if (_timeOver==0) {
        [self checkIfGameOver];
    }
}
于 2012-11-20T08:38:39.600 に答える