Reputation: 29
I am creating a type of stopwatch app. Now to have it "Running" in the background I save the NSDate
when the button is pressed and compare it to when the user comes back.
The point where i'm at now is using a popup asking to erase all the values if the timers aren't running. The timer saves a NSString
to NSUserDefaults
when it is pressed to indicate running vs not running. here is the code I have tried:
NSString *TS = [prefs objectForKey:@"Run"];
NSString *TS1 = [prefs objectForKey:@"Run1"];
NSString *TS2 = [prefs objectForKey:@"Run2"];
NSString *TS3 = [prefs objectForKey:@"Run3"];
NSString *TS4 = [prefs objectForKey:@"Run4"];
NSString *TS5 = [prefs objectForKey:@"Run5"];
NSString *TS6 = [prefs objectForKey:@"Run6"];
NSString *TS7 = [prefs objectForKey:@"Run7"];
NSString *TS8 = [prefs objectForKey:@"Run8"];
NSString *TS9 = [prefs objectForKey:@"Run9"];
NSString *TS10 = [prefs objectForKey:@"Run10"];
NSString *TS11 = [prefs objectForKey:@"Run11"];
NSString *TS12 = [prefs objectForKey:@"Run12"];
NSString *TS13 = [prefs objectForKey:@"Run13"];
NSString *TS14 = [prefs objectForKey:@"Run14"];
NSString *TS15 = [prefs objectForKey:@"Run15"];
NSString *TS16 = [prefs objectForKey:@"Run16"];
NSString *TS17 = [prefs objectForKey:@"Run17"];
// NSString *TS18 = [prefs objectForKey:@"Run18"];
if ([TS isEqual: @"NotRunning"] | [TS1 isEqual: @"NotRunning"] |[TS2 isEqual: @"NotRunning"] |[TS3 isEqual: @"NotRunning"] | [TS4 isEqual: @"NotRunning"] |[TS5 isEqual: @"NotRunning"] | [TS6 isEqual: @"NotRunning"] | [TS7 isEqual: @"NotRunning"] | [TS8 isEqual: @"NotRunning"] | [TS9 isEqual: @"NotRunning"] | [TS10 isEqual: @"NotRunning"] |[TS11 isEqual: @"NotRunning"] | [TS12 isEqual: @"NotRunning"] | [TS13 isEqual: @"NotRunning"] |[TS14 isEqual: @"NotRunning"]|[TS15 isEqual: @"NotRunning"]|[TS16 isEqual: @"NotRunning"]|[TS17 isEqual: @"NotRunning"])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Would you like to clear everything?",@"") message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"NO",@"") otherButtonTitles:NSLocalizedString(@"YES",@""), nil];
alert.alertViewStyle = UIAlertViewStyleDefault;
alert.tag = 99;
[alert show];
}
any help is greatly appreciated! so thanks in advance :)
Upvotes: 0
Views: 75
Reputation: 1278
BOOL allNotRunning = YES;
for(int index = 1;index < 19; index++){
NSString *key = index == 1 ? "Run" : [NSString stringWithFormat:"Run%d", index];
if(![[prefs objectForKey:key] isEqualToString:@"NotRunning"]){allNotRunning = NO;}
}
if(allNotRunning){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Would you like to clear everything?",@"") message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"NO",@"") otherButtonTitles:NSLocalizedString(@"YES",@""), nil];
alert.alertViewStyle = UIAlertViewStyleDefault;
alert.tag = 99;
[alert show];
}
Upvotes: 1