12-03-2011, 01:13 PM
#1 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
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];
12-03-2011, 01:19 PM
#2 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
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.
12-03-2011, 01:24 PM
#3 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
i know how work a timer
but i want the UIDatePicker set the time...
how to do that ?
12-03-2011, 01:27 PM
#4 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
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.
12-03-2011, 01:32 PM
#5 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
its ok
if i have this:
Code:
-(void)Ten{
//My action
}
how to use NSTimeInterval to do this "void"?
12-03-2011, 01:33 PM
#6 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
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.
12-03-2011, 01:37 PM
#7 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
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.
12-03-2011, 01:44 PM
#8 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
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 .
12-03-2011, 01:49 PM
#9 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
can you give me an example or a link guide ?
12-03-2011, 01:51 PM
#10 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
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.
12-03-2011, 01:57 PM
#11 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
i am a beginner of xcode and i have no idea how to begin...
12-03-2011, 02:02 PM
#12 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
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.
12-03-2011, 02:20 PM
#13 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
It's complicated for me...
i can't understand
Can you get me a simple example ? or a guide or a project example ?
12-03-2011, 02:24 PM
#14 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
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 .
12-03-2011, 02:36 PM
#15 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
thank you
now i understanding...
now how to do the NSTimeInterval ?
12-03-2011, 02:41 PM
#16 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
"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.
12-03-2011, 02:45 PM
#17 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
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 .
12-03-2011, 03:21 PM
#19 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 129
ok, i found an other way to do that...
thank you very much
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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