Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-28-2010, 02:49 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 4
longerapps is on a distinguished road
Default NSTimer help?

NSTimer in iphone program?
I am developing a viewbased program for iphones. I have lots of .xib files.
It is basically a trivia game.
I am trying to make it so that the program times how long it takes them to get to the end. How can i get one timer to show up on all the pages and then stop once they get the last question right(and start with a button at the beginning) and display the time.

Please be as descriptive as you can because I've never developed an iphone app before and im trying to learn c/objective c as i make this app.


thanks alot!
longerapps is offline   Reply With Quote
Old 12-28-2010, 03:01 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Put the time in the app delegate and access it from there. Or create a Singleton class for the timer. Searching for those terms on the forum will get you lots of results in previous threads.
baja_yu is offline   Reply With Quote
Old 12-28-2010, 03:16 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Benicia, CA
Age: 50
Posts: 152
That Don Guy is on a distinguished road
Default

If you don't want to display the time as the app is running, then you don't want an NSTimer - instead, you want an NSDate variable that is set to [NSDate date] when the clock starts; if you call it, say, startTime, you can then use something like:

NSTimeInterval elapsedTime = -[StartTime timeIntervalSinceNow]

to get the number of seconds (with fractional seconds) between when you started and when you finished. (Note the minus sign after the equals sign; since Start Time is in the past, using timeIntervalSinceNow returns a negative number.)

-- Don
That Don Guy is offline   Reply With Quote
Old 12-28-2010, 03:19 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 4
longerapps is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Put the time in the app delegate and access it from there. Or create a Singleton class for the timer. Searching for those terms on the forum will get you lots of results in previous threads.


I tried putting code into delegate but then what .xib file do i tag the label (the one that shows the time). None of the .xibs have a "connection" for the time
longerapps is offline   Reply With Quote
Old 12-28-2010, 03:20 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 4
longerapps is on a distinguished road
Default

Quote:
Originally Posted by That Don Guy View Post
If you don't want to display the time as the app is running, then you don't want an NSTimer - instead, you want an NSDate variable that is set to [NSDate date] when the clock starts; if you call it, say, startTime, you can then use something like:

NSTimeInterval elapsedTime = -[StartTime timeIntervalSinceNow]

to get the number of seconds (with fractional seconds) between when you started and when you finished. (Note the minus sign after the equals sign; since Start Time is in the past, using timeIntervalSinceNow returns a negative number.)

-- Don
thanks but i am trying to have the time shown
longerapps is offline   Reply With Quote
Old 12-28-2010, 04:09 PM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Take a look at this thread by DuncanC http://www.iphonedevsdk.com/forum/ip...n-objects.html
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
newbie, nstimer, sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 357
9 members and 348 guests
akphyo, blueorb, fredidf, iAppDeveloper, iGamesDev, Kirkout, MarkC, mottdog, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0