5

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.

1

2 Answers 2

2

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"];
    }
}
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.