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-03-2011, 01:13 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default How to combine UIDatePicker with NSTimer

how to set the time of UIDatePicker (count down) to a timer ??


Code:
[NSTimer scheduledTimerWithTimeInterval:(What i need to put here ?) target:self selector:@selector(Now) userInfo:nil repeats:NO];
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 01:19 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

The number you should put there is the interval at which you want the timer to fire. For example, if you specify 1, the timer will fire every second.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-03-2011, 01:24 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

i know how work a timer
but i want the UIDatePicker set the time...
how to do that ?
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 01:27 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Oh sorry, UIDatePicker's have a NSTimeInterval named countDownTimer.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-03-2011, 01:32 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

its ok
if i have this:
Code:
-(void)Ten{
	//My action
}
how to use NSTimeInterval to do this "void"?
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 01:33 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

What is the method supposed to do?
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-03-2011, 01:37 PM   #7 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

i want to do just like the Alarm clock app...
the UIDatePicker will set time to ring/show alert... and after the time was done it will to this action.
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 01:44 PM   #8 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

So you want to set an alarm with a date? Then use NSObject's performSelector:withObject:afterDelay:. To find the delay, find the time interval between the target date (your alarm date) and the current date using timeIntervalSinceNow on your target date.

Edit: On a related note, performSelector is basically the same thing as using a timer but timer's are usually for repeating things.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 12-03-2011 at 01:48 PM.
Domele is offline   Reply With Quote
Old 12-03-2011, 01:49 PM   #9 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

can you give me an example or a link guide ?
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 01:51 PM   #10 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Start off by getting the time interval by calling timeIntervalSinceNow on the date you get from the date picker. Post the code for that.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-03-2011, 01:57 PM   #11 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

i am a beginner of xcode and i have no idea how to begin...
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 02:02 PM   #12 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Okay so you don't know how to retrieve the date from the UIDatePicker? Okay well a UIDatePicker has a NSDate property named date. To access properties, there are two ways. Since properties automatically generate setters and getters named after the ivar name, you can access it by calling the ivar name on the object.
Code:
AnObject *object = [anotherObject theIvarName];
Of course you can customize the name of the generate setter but for now, just assume you can't.

Another way is use dot notation. The format for dot notation is anObjectPointerName.theIvarName.

So try to get a date from the UIDatePicker.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-03-2011, 02:20 PM   #13 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

It's complicated for me...
i can't understand
Can you get me a simple example ? or a guide or a project example ?
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 02:24 PM   #14 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Okay here is how you get a UIImage property named "image" from a UIImageView.
Code:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage named:"MyFakeImage.png"]];
UIIMage *imageInImageView = imageView.image;
Now do the same for your UIDatePicker but don't alloc it like I did because you'll be creating a new instance and that's not what we want. You need to get a reference to you existing date picker. If it's created in IB, setup an IBOutlet connection and if not, make an ivar. If you still have no idea, look at this tutorial on how to use a UIDatePicker: iPhone UIDatePicker Tutorial | James Sasitorn. It will show you how to retrieve the date.

Edit: I feel nice and I'm going to explain how to do what you're after.
Code:
NSDate *alarmFireDate = datePicker.date;
See how it follows pointerName.ivarName.

Then you need to get in seconds, how long this date is away from the current date.
Code:
NSDate *alarmFireDate = datePicker.date;
NSTimeInterval *differenceFromNow = [alarmFireDate timeIntervalSinceNow];
To call a method on an object, you surround it with brackets and type out the method name. [yourObject theMethodName];

Then you use the difference to tell your view controller or whichever object is managing your alarms to call a method once we reach our fire date. This object will need to stay alive otherwise the alarm will not fire.
Code:
NSDate *alarmFireDate = datePicker.date;
NSTimeInterval *differenceFromNow = [alarmFireDate timeIntervalSinceNow];
[yourObjectThatHandlesAlarms performSelector:@selector(theMethodThatWillGetCalledWhenTheAlarmDateIsReached) withObject:nil afterDelay:differenceFromNow];
That will make your object that handles alarm call the method "theMethodThatWillGetCalledWhenTheAlarmDateIsReach ed" on itself.
Code:
- (void)theMethodThatWillGetCalledWhenTheAlarmDateIsReached {
//show the user that the alarm has fired or whatever you want to do
}
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 12-03-2011 at 02:37 PM.
Domele is offline   Reply With Quote
Old 12-03-2011, 02:36 PM   #15 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

thank you
now i understanding...

now how to do the NSTimeInterval ?
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 02:41 PM   #16 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

"do the NSTimeInterval"? I think you'd need the object's consent first and it doesn't have a method for that unfortunately.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-03-2011, 02:45 PM   #17 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

now when i the label show me the date(iPhone UIDatePicker Tutorial | James Sasitorn)

i want that do an action when the time is done.



edit: i didn't see your edit and your example...

Last edited by jordanmeir; 12-03-2011 at 02:52 PM.
jordanmeir is offline   Reply With Quote
Old 12-03-2011, 02:51 PM   #18 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Okay so use a NSDateFormatter. Allocate it. Set the format string. Format codes can be found here: Stepcase Blog Archive Format String for the iPhone NSDateFormatter. Then use stringFromDate: using the alarm date as the argument. Example can be found here: Date Formatter Examples – Take 1: NSDateFormatter
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 12-03-2011, 03:21 PM   #19 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 129
jordanmeir is on a distinguished road
Default

ok, i found an other way to do that...
thank you very much
jordanmeir is offline   Reply With Quote
Reply

Bookmarks

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: 398
14 members and 384 guests
7twenty7, AppsBlogger, Clouds, David-T, Duncan C, EvilElf, HemiMG, heshiming, iekei, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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