Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
- Subject: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
- From: "Chunk 1978" <email@hidden>
- Date: Wed, 10 Dec 2008 19:03:30 -0500
i believe i painted myself into a corner here... i have a
NSPopUpButton with 3 items. 1 Hour, 2 Hours, 3 Hours. each item has
respected tag numbers 1, 2 and 3. i'm attempting to print out time
remaining but i can only get as far as displaying seconds remaining
with this: NSLog(@"%.2d Seconds Remaining", (hoursSelected -
second)); but i would like for the log to output @"%.2d Hours, %.2d
Minutes and - Seconds Remaining"; i can't wrap my head around it,
and i fear that my trying to be as if/else statementless as possible
by using the tag numbers of the PopUp Menu is causing me problems.
-=-=-=-=-
-(int)timeMenuSelection
{
return [[menu selectedItem] tag];
}
- (IBAction)startTimer:(id)sender
{
startTime = [NSDate timeIntervalSinceReferenceDate];
[killTimer invalidate];
[killTimer release];
killTimer = nil;
killTimer = [[NSTimer scheduledTimerWithTimeInterval:1 target:self
selector:@selector(updateTime:) userInfo:nil repeats:YES] retain];
}
- (void)updateTime:(NSTimer *)theTimer
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval interval = now - startTime;
int second = (int)interval;
//Tag #1 x 3600 Seconds = 3600 Seconds = 2 Hours.
//Tag #2 x 3600 Seconds = 7200 Seconds = 2 Hours.
//Tag #3 x 3600 Seconds = 10800 Seconds = 3 Hours.
int hoursSelected = ([self timeMenuSelection] * 3600);
if (second <= hoursSelected)
{
NSLog(@"%.2d Seconds Remaining", (hoursSelected - second));
}
else
{
NSLog(@"TIME'S UP!");
[killTimer invalidate];
[killTimer release];
killTimer = nil;
}
}
-=-=-=-=-
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden