Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple alert views being sent crashes the application
    text
    copied!<p>I'm trying to send 2 alert views to the main thread but if the first alert view has not been dismissed and the second shows up, the application crashes. how would i avoid this?</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; self.date1 = [NSDate dateWithTimeInterval:[testTask timeInterval] sinceDate:[NSDate date]]; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]; [timer fire]; } -(void)timerAction:(NSTimer *)t{ NSDate *now = [NSDate date]; NSDateComponents *components = [gregorianCalendar components:NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:now toDate:self.date1 options:0]; NSString *timeRemaining = nil; if([now compare:self.date1] == NSOrderedAscending){ timeRemaining = [NSString stringWithFormat:@"%02d:%02d:%02d", [components hour], [components minute], [components second]]; NSLog(@"works %@", timeRemaining); } else { timeRemaining = [NSString stringWithFormat:@"00:00:00"]; [self.timer invalidate]; self.timer = nil; UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:[testTask taskName] message:@"Time is up!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; [alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES]; NSLog(@"ended"); } timerLabel.text = timeRemaining; [timerLabel setNeedsDisplay]; [self.view setNeedsDisplay]; } </code></pre>
 

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