add second field when uipickerview in countdowntimer mode in iPhone - iphone

i have a functionility for show count down timer in format, but when uidatepicker in count down timer mode , it show only HH:MM.
how i can add a extra field for second in uidatepickerview.

how i can add a extra field for second in uidatepickerview.
You can't. UIDatePicker only displays hours and minutes in countdown mode. If you need to display seconds as well, you'll have to recreate it yourself using a UIPickerView.
As always, you should file an enhancement request to request this functionality.

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 2;
}
it will create section in your picker view.

Related

Setting the Count Down Timer in Swift 3

I'm using Date Picker, which is set to Count Down Timer mode. By default it displays the current time. How would I set it to display a specific time on start up? Thanks in advance.
You can use date property
UIDatePicker > date
Use this property to get and set the currently selected date

iOS 5 Picker View update based on selection?

I am working on a project where I want to have a picker view with 3 columns.
In the first column I want the user to select a letter.
Once the letter is selected I want the second column to update with a list of last names that start with that letter. When a last name is selected I want the third column to update with a list of first names who have the selected last name.
Can this even be done? Help!?
Get the letter that they selected using this pickerview delegate method:
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
You could load the next picker at this point but it would be better to populate the next picker when the done button on each picker is selected:
This is a nice SO post that describes how to use picker views very well: Dismissing UIPickerView with Done button on UIToolBar

How select value initally when picker view appear?

I have set a picker view appearance on text field begin editing function and hide keyboard. Now problem is that when picker view appear then it show selection indicator on first value but that value not show in text field. I want that when user click on text filed then picker view appear and value from picker will show in text field where selection indicator place. How do that? Suppose i have four value in same order 0,1,2,3. Now when picker view appear then selection indicator is at on '0' value. But to get that value we have to scroll picker view and come back to '0' then it show that value in text field. Why it is occurs? And how get value automatically?
Thanks in advances...
Well, there is no connection between your picker view and the text field - you have to make it yourself.
There are two things to consider:
1) Your text field already contains a value, let's say "1". When you open the picker, you can set it to this value already with the function
[yourPicker selectRow:1 inComponent:0 animated:false]
, assuming your data array for the picker is [0, 1, 2, 3]. In your case, to make the text field contain the value 0, just call
[textField setText:#"0"]
2) When you are finished with the picker, it calls the delegate function
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
So you have to make your view implement the UIPickerViewDelegate protocol, implement the above delegate function in it and set the view as the picker view's delegate.
In the delegate function you can get the value the user picked (using row to access your data array values) and set this value in your textfield.

How do I make a picker appear to spin around multiple times?

I am trying to make a picker appear to spin around multiple times before landing on a particular row. I have tried using for and do while loops. I have even tried calling multiple methods in succession, but each time, the picker only appears to reload once even though I am telling it to reload multiple times before finally landing on a selected row like this:
int newValue = random() % [self.inputNames count];
[payPicker selectRow:newValue inComponent:0 animated:YES];
[payPicker reloadComponent:0];
NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 2.0 ];
[NSThread sleepUntilDate:future];
newValue = random() % [self.inputNames count];
[payPicker selectRow:newValue inComponent:0 animated:YES];
[payPicker reloadComponent:0];
[NSThread sleepUntilDate:future];
I do the above about three or four times and each time the picker only appears to reload once and goes to the final selected row. Is there something special I have to do or is it possible at all to make the picker appear to spin around and around? If I could even get it to jump randomly between the row choices before landing on one, I would be fine with that.
Thanks!!
Don't sleep the UI thread. No animation will start until you exit this method, after all your sleeping. So return from the method with the first request for the picker to animate. Do subsequent picker animation requests in timer callbacks after the previous picker animation has finished. Rinse and repeat as necessary.
The way other apps do this is by not using a real picker at all, but overlaying the picker control with an animated image sequence which just happens to look like a picker spinning. Then remove the fake animation to show an identical looking but real picker underneath. The advantage of your own animated cartoon is that you can make the fake picker spin in ways that a real picker can't.
Perhaps you could try selecting random rows before selecting your actual row. For example, if you want to select row 0, select rows in the following order - 9, 2, 15, 0. I don't think picker view will rotate if it is already on the row it is supposed to go to.
Also, you should select the rows every time after your pickerView:didSelectRow:inComponent: method hits.

UIDatePicker UIDatePickerModeCountDownTimer mode can't select zero minutes

I'm using a UIDatePicker in UIDatePickerModeCountDownTimer mode which lets the user select hours and minutes, but it won't let the user select zero hours and zero minutes.
If the hours are set to zero and the user tries to pick zero minutes, it automatically jumps to 01.
I've researched the docs and nothing seems to allow me to do that, short of creating a custom picker.
The problem with creating a custom picker is that I lose the title in the selection indicator (hours, minutes) and there doesn't seem to be a way of adding those either.
I've been looking for an answer for the past 2 days! I can't believe UIPickerView doesn't have a property to set the title for indicators for each section.
Any help would be appreciated.
If you do choose to create a custom UIPicker you can use the titleForRow method to change the labels in each component (such as "hours", "minutes", etc).
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if(component == 0){
return [NSString stringWithFormat:#"Hours"];
}else if (component == 1){
return [NSString stringWithFormat:#"Minutes"];
}
}
I suppose a count-down timer is not intended for not counting down. So, you have at least one minute. If you do not want a timer at all, you need an additional switch for enabling the count-down.
BTW., I stumbled over a kind of an opposite problem. I set the interval to 5 minutes. Then, I can select 0 minutes. I wanted to know how to prevent a user from setting 0. In fact, in my case I get also 1 minute, only the picker shows 0.
So, you could use this to let the user choose 0 in the picker and then interpret the 1 minute as 0 in your code. But I wouldn't do this, since the behavior of the picker might change in the future. I consider the current behavior a bug.