1

我在使NSTimer. NSTimer我用下面的函数初始化 a 。

-(void) initLTTimer{
    [self shutLTTimer];
    [self setQuestion:questionCounter];
    isQuestionAttempt=NO;
    tmLeftTime=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLeftTime:) userInfo:nil repeats:YES];
    NSLog(@"Timer Initialized");
}

updateLeftTime此外,我在其选择器中调用了一个函数。

- (void)updateLeftTime:(NSTimer *)theTimer {
    NSLog(@"%d",timeCounter);
    timeCounter+=1;
    tfLeftTime.text=[NSString stringWithFormat:@"%d", (QUESTION_TIME_LIMIT-timeCounter)];
    if (timeCounter>=QUESTION_TIME_LIMIT) {
        if (isQuestionAttempt==NO) {
            [self increaseDropShots];
        }
        [self setQuestionBg];
        timeCounter=0;
        [self shutLTTimer];
        [self updateQuestion:nil];
    }

}

该函数[self increaseDropShots];在上述函数中调用。这是这个函数的代码

-(void)increaseDropShots
{
    NSString *imgName = @"DactiveRetake";
    if (IS_IPAD) {
        imgName = [imgName stringByAppendingString:@"_ipad"];
    }
    wrongAttemp+=1;
    for (int i =1; i<=wrongAttemp; i++ ) 
    {
        UIImageView *img=(UIImageView *)[self.view viewWithTag:i+50];
        [img setImage:[UIImage imageNamed:imgName]];
    }
    NSLog(@"Question dropped counter: %d",wrongAttemp);
    if (wrongAttemp == 3)
    {
        [self shutLTTimer];
        [CommonFunctions initGlobalVars];
        [Bgplayer stop];
        [Bgplayer release];

        OverPageViewController *opvc=[[OverPageViewController alloc] initWithNibName:[CommonFunctions getXIBFile:@"OverPageViewController"] bundle:[NSBundle mainBundle]];
        [self.navigationController pushViewController:opvc animated:YES];
        [opvc release];

    }

}

在这个函数中,我正在杀死这个计时器,但我做不到。

   -(void) shutLTTimer{
    if ([tmLeftTime isValid]) {
        [tmLeftTime invalidate];
        tmLeftTime=nil;
    }

这是我的应用程序的整个场景

请帮助我这是什么问题。

4

1 回答 1

1

在评论中对话后回答

代码是否肯定会到达这条线,[tmLeftTime invalidate];?您可以使用断点或NSLog.

于 2011-09-27T08:06:52.493 回答