Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
- Subject: Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
- From: Nathan Day <email@hidden>
- Date: Thu, 11 Dec 2008 11:22:38 +1100
You need something like
NSLog(@"%.2d Hours, %.2d Minutes and - Seconds Remaining",
hoursSelected-seconds/3600, (hoursSelected*60-seconds/60)`,
(hoursSelected*3600-seconds)` );
On 11/12/2008, at 11:03 , Chunk 1978 wrote:
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
_______________________________________________
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