开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜