UIDatePicker错误? UIControlEventValueChanged达到最小内部 [英] UIDatePicker bug? UIControlEventValueChanged after hitting minimum internal

查看:71
本文介绍了UIDatePicker错误? UIControlEventValueChanged达到最小内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一种奇怪的效果,肯定看起来像是iOS7中的错误-但是经常在过去,当我以为我发现了Apple API中的错误时,事实证明这是我自己的误解.

I've run into a weird effect that sure looks like a bug in iOS7 -- but often in the past, when I have thought I found a bug in Apple's APIs, it has turned out to be my own misunderstanding.

我有一个带有datePickerMode = UIDatePickerModeCountDownDownTimer和minutesInterval = 5的UIDatePicker.我将持续时间初始化为1小时,并提供给用户,在那里它显示为带有小时和分钟的两列选择器. (到目前为止很好.)

I have a UIDatePicker with datePickerMode = UIDatePickerModeCountDownTimer and minuteInterval = 5. I initialize the duration to 1 hour, and present it to the user, where it appears as a two-column picker with hours and minutes. (So far so good.)

用户正在考虑"20分钟",因此将小时"列滚动到0.这时,选择器读取0小时0分钟,而iOS7对此并不满意,因此它会自动将分钟轮滚动到5我的UIControlEventValueChanged处理程序被调用,并且countDownDuration读取5分钟. (仍然很好.)

The user is thinking "20 minutes," and so scrolls the Hour column to 0. At this point the picker reads 0 hours and 0 minutes, and iOS7 is not cool with that, so it automatically scrolls the minute wheel to 5. My UIControlEventValueChanged handler gets invoked, and the countDownDuration reads 5 minutes. (Still good.)

现在,用户抓住了分钟轮并将其拖到20.AND ...我的UIControlEventValueChanged处理程序没有被调用. (不好)

Now the user grabs the minute wheel and drags it to 20. AND... my UIControlEventValueChanged handler does not get called. (Bad.)

如果此时我在UI中还有其他事件检查日期选择器,那么我确实会看到countDownDuration设置为20.但是,在更改的那一刻,我无法得知用户对其进行了更改.这是非常可重复的:它总是在选择器拒绝将其设置为0(前进到5分钟)之后的第一次更改时发生.

If I have some other event in the UI check the date picker at this point, I do see the countDownDuration is set to 20. But I had no way of knowing that the user changed it, at the moment it was changed. This is very repeatable: it always happens on the first change AFTER the picker refuses to be set to 0 (advancing itself to 5 minutes).

请注意,这是在iOS7中;在iOS6中不会发生这种情况(可能是因为那里的选择器完全可以将内容设置为0分钟).

Note that this is in iOS7; it does not occur in iOS6 (perhaps because the picker there is perfectly content to be set to 0 minutes).

那么...我在这里想念什么吗?还是这是iOS7中的真正错误?在后一种情况下,有没有人比让某个计时器定期检查当前时间间隔更了解变通方法?

So... am I missing something here? Or is this a genuine bug in iOS7? And in the latter case, does anybody know a work-around better than having some timer periodically check the current interval?

推荐答案

我还可以确认在UIDatePickerModeCountDownTimer模式下使用iOS 7.0.3 UIDatePicker时存在错误.用户第一次通过滚动滚轮更改值时,选择器不会触发与UIControlEventValueChanged事件关联的目标动作.可以很好地用于以后的更改.

I can also confirm that the iOS 7.0.3 UIDatePicker has a bug in it when used in UIDatePickerModeCountDownTimer mode. The picker does not fire the target-action associated with the UIControlEventValueChanged event the first time the user changes the value by scrolling the wheels. It works fine for subsequent changes.

下面是一个有效的解决方法.只需将将countDownDuration初始值设置在调度块中的代码封装到主循环中即可.每当车轮旋转到新值时,您的目标动作方法都会触发.这种方法几乎没有开销,并且在iPhone 4和iPad 4上效果很好.

Below is an efficient workaround. Simply enclose the code that sets the initial value of the countDownDuration in a dispatch block to the main loop. Your target-action method will fire every time the wheels are rotated to a new value. This approach has almost no overhead and works quite well on an iPhone 4 and iPad 4.

dispatch_async(dispatch_get_main_queue(), ^{
    self.myDatePicker.countDownDuration = (NSTimeInterval) aNewDuration ;
});

迅速5:

DispatchQueue.main.async {
    self.myDatePicker.countDownDuration = aNewDuration
}

这篇关于UIDatePicker错误? UIControlEventValueChanged达到最小内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆