1

私は長い間アプリでこれをやろうとしてきましたが、うまくいきません。誰かが私を助けて、私がそれを行う方法に関するコードを投稿してください。私が起こる必要があるのは、UITextField のテキストが UILabel と等しいときです。ありがとう

h. ビューコントローラー

@interface AlphabetSceneViewController : UIViewController {

UILabel *stopWatchLabel;
NSTimer *stopWatchTimer;
NSDate *startDate;

IBOutlet UILabel *wordToType;
IBOutlet UITextField *wordTyped;

とm。ビューコントローラー

    - (void)updateTimer
{
    NSDate *currentDate = [NSDate date];
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
    NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"mm:ss.SSS"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
    NSString *timeString=[dateFormatter stringFromDate:timerDate];
    stopWatchLabel.text = timeString;
}

- (IBAction)onStartPressed:(id)sender {
    startDate = [NSDate date];

    stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
                                                      target:self
                                                    selector:@selector(updateTimer)
                                                    userInfo:nil
                                                     repeats:YES];
}

- (IBAction)onStopPressed:(id)sender {    

    [stopWatchTimer invalidate];
    stopWatchTimer = nil;
    [self updateTimer];

    if ([wordToType.text isEqualToString:@"stop"]) {

    }

}

大変助かりました!

4

1 に答える 1

1

私はそれを行う方法を見つけました。知りたい人のためにコードを掲載します。これは .m ファイルのコードにすぎず、アラート ビューは、タイマーが停止したときにユーザーが持っていた時間でアラートを表示するようにするための、最後に追加されたほんの少しのコードです。

- (IBAction)stopTimer:(id)sender {

    if([wordTyped.text isEqualToString:wordToType.text]){

        [stopWatchTimer invalidate];
        stopWatchTimer = nil;
        [self updateTimer];


        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Nice Work" message:[NSString stringWithFormat:@"Good Job! You're time to type the alphabet was %@. Let's see if you can do better...", stopWatchLabel.text]
                                                       delegate:self cancelButtonTitle:@"Main Menu" otherButtonTitles: nil];

        [alert show];
    }
}
于 2012-06-17T08:33:38.783 に答える