0

ボタン アクションから imagePickerController をロードする viewController があります。imagePickerController が読み込まれると、あらかじめ決められたデータを含む 2 つのラベルがオーバーレイとともに表示されます。1 つは timerLabel で、もう 1 つは titleLabel です。imagePickerController が最初にロードされると、両方のラベルが正しいデータで表示されますが、しばらくすると timerLabel データは消えますが、ラベル自体はまだそこにあります。私の refreshLabel メソッドでは、NSLogged timerLabel は正しいですが、startDate と timeLeft の NSLog に到達すると (null) を返します。何か案は?ありがとう!

    - (IBAction)startCamera:(id)sender {
        if (self.image == nil &&  [self.videoFilePath length] == 0) {
            self.imagePickerController = [[UIImagePickerController alloc] init];
            self.imagePickerController.delegate = self;
            self.imagePickerController.allowsEditing = NO;
            self.imagePickerController.videoMaximumDuration = 10;

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            }
            else {
                self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            }
            self.imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePickerController.sourceType];
            [self presentViewController:self.imagePickerController animated:NO completion:nil];}

        [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
        self.overlayView.frame = CGRectMake(160,8,0,0);
        self.imagePickerController.cameraOverlayView = self.overlayView;

        NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSString *deadline = [NSString stringWithFormat:@"%@/deadline.txt",
                              documentsDirectory];
        NSString *name = [NSString stringWithFormat:@"%@/name.txt",
                               documentsDirectory];
        NSError *fileError;
        titleLabel.text = [NSString stringWithContentsOfFile:name
                                                    encoding:NSASCIIStringEncoding
                                                       error:&fileError];
        timerLabel.text = [NSString stringWithContentsOfFile:deadline
                                                    encoding:NSASCIIStringEncoding
                                                       error:&fileError];
        if(fileError.code == 0){
            NSLog(@"deadline.txt was read successfully with these contents: %@,",
                  timerLabel.text);
            NSLog(@"name.txt was read successfully with these contents: %@,",
                  titleLabel.text);}


     NSLog(@"timer label %@", timerLabel.text);

    [NSTimer scheduledTimerWithTimeInterval:1
                                     target:self
                                   selector:@selector(refreshLabel)
                                   userInfo:nil
                                    repeats:YES];
}

-(void)refreshLabel {
    NSLog(@"timer label %@", timerLabel.text);

    NSDate *startDate = [self.formatter dateFromString:timerLabel.text];
    NSDate *timeLeft = [startDate dateByAddingTimeInterval:-1];

    NSLog(@"start time %@",startDate);
    NSLog(@"time left %@",timeLeft);

    NSTimeInterval totalCountdownInterval =1;
    NSTimeInterval elapsedTime = [timeLeft timeIntervalSinceNow];
    NSTimeInterval remainingTime = totalCountdownInterval - elapsedTime;

    self.timerLabel.text = [self.formatter stringFromDate:timeLeft];

    if (remainingTime <= 0.0) {
        //dismiss controller and set to homecontroller at tabBar index 1
    }
}
4

0 に答える 0