Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rajneesh.deora

macrumors newbie
Original poster
Aug 19, 2008
21
0
hi all ,

i am new to iphone development so plz do assist me ,i need to display a timer (as in screenshot)which counts minutes and hours only, starting from 1 minute and going up to 24 hours. Once the timer hits 24 hours it stops and resets at zero. i didn't find any such help all over the internet plz do help me its very urgent .
I have attach a screenshot for the same.
If you peoples can provide me code for the same the same i will be very thankful to you .


thanks in advance
 

Attachments

  • timer.PNG
    timer.PNG
    18.3 KB · Views: 186

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Again you don't seriously expect us to write that for you? Put some effort in. None of these things are one line of code. If you want to write software then you are expected to be able to break the problem down into smaller steps and then turn those into code. I suggest you go back to the start and actually learn how to program and then how to use the frameworks. This is simply ridiculous.
 

Luke Redpath

macrumors 6502a
Nov 9, 2007
733
6
Colchester, UK
I don't think you're going to learn anything if people just hold your hand and show you how to do everything; that said, I do have some sample code that I can post when I get home (it's on my laptop) to help you get started as it's one of the first things I learnt to do just to get a feel of ObjC and the SDK basics.

If you want to have a go at working it out, here's a few hints: look at the documentation for NSTimer and couple [NSString stringWithFormat] with some basic arithmetic to convert seconds into hours and minutes for display. You can then wrap this up in a really simple Counter/Timer class - this becomes your "model". You'll need a view controller and a nib file for the view/controller side of things. Read the "View Controller Programming Guide" on the Apple dev site to get an idea of how to hook it all up.
 

Ron C

macrumors member
Jul 18, 2008
61
0
Chicago-area
About that display

7-segment displays are well known. Probably the easiest thing here is to map each digit value to 7 bi-stated values, each indicating if the corresponding segment should be displayed in an ON or OFF state. Note here that ON and OFF are for you to define. OFF may mean invisible or "shadowed" or lighter green, while ON can mean solid or purple or blinky.

Convert the time number into a string; skip the ":" when looking at each digit. Map the character '0' to something like ON,ON,ON,ON,ON,ON,OFF, and a '2' to ON,ON,OFF,ON,ON,OFF,ON, where I've indexed the segmenets starting at the top cross segment then going clockwise around the display, with the middle cross-segment as the last value. (The traditional trick with mapping characters to indexes is to subtract, as in arithmetic subtract, the value of the character '0' from the number character. Since we're all ASCII here, '0' is hex 0x30. '0'-'0' = 0, '1'-'0' = 1, ....)

As homework, you write the code and share it with us. For extra credit, post a screen shot from the iPhone Simulator.

Ron C
 

drivefast

macrumors regular
Mar 13, 2008
128
0
rather than separate images for the 7 segments, i would use a separate image for each of the 10 possible display states of a digit, and change the image every second. but that is not going to be your major issue. if you plan to keep the timer on for 24 hours and more, you will have to ask your users not to launch another application while yours is, uh, counting. remember, iphone is one application at a time. therefore you would have to think how you would save the data when your application quits, and restore it when you restart it. you would have to design your application about the 1-second timer events, as well as around the timestamp when your user started the timer. get some inspiration on how to work with the timer from the metronome sample app provided by apple, and regarding the user interface, from the almighty UICatalog sample. for date manipulation internally, CFDate is your friend.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.