Note that there are some explanatory texts on larger screens.

plurals
  1. PONSTimer displayed in label then disappears?
    primarykey
    data
    text
    <p>I have a viewController that loads my imagePickerController from a button action. When the imagePickerController loads it should display, with an overlay, two labels with predetermined data. One is timerLabel and the other is titleLabel. Both labels are displayed with the correct data when the imagePickerController first loads but after only a moment, the timerLabel data disappears but the label itself is still there. In my refreshLabel method, the NSLogged timerLabel is correct but when it gets to the NSLog for startDate and timeLeft it returns (null). Any ideas? thanks!</p> <pre><code> - (IBAction)startCamera:(id)sender { if (self.image == nil &amp;&amp; [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:&amp;fileError]; timerLabel.text = [NSString stringWithContentsOfFile:deadline encoding:NSASCIIStringEncoding error:&amp;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 &lt;= 0.0) { //dismiss controller and set to homecontroller at tabBar index 1 } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload