7

I have a UIPickerView with multiple components. Some values are grayed out, and my pickerView:didSelectRow:inComponent honors this by shifting the picker component in question to the nearest valid value, much as UIDatePicker moves from "30" to "28" when you select "February". Then it calls a delegate method to announce the adjusted value.

When my adjuster method calls my UIPickerView's selectRow:inComponent:animated:YES, the value on screen is correct, but the values from selectedRowInComponent: are stale (from before the adjustment for gray values). However, if I call selectRow:inComponent:animated:NO, the returned values are correct, but the lack of animation is jarring.

I've tried wrapping the adjustment in a beginAnimations:/commitAnimations block and catching the values in UIView's +animationDidStopSelector, but I still get stale values. Has anyone run into this before?

The problem is easy to duplicate.

[picker selectRow:newValue inComponent:i+offset animated:YES];

retValue = [picker selectedRowInComponent:i+offset];

If you have YES to animated it, then retValue is 0 on mind (you call it stale). Changing to NO, retValue will be the same as newValue.

4

1 回答 1

1

我没有注意到这一点,但一个简单的技巧可能是执行动画操作,然后一旦动画完成,只需在没有动画的情况下再次执行。那么结果selectedRowInComponent应该是正确的。

但是,从您的测试代码看来,它返回了正确的结果。如果您要求选取器选择动画行,那么在动画完成之前不会设置新值,因此如果您在刚开始动画后立即询问所选行(无论如何直到下一个 runloop 才会开始),那么您将得到旧的结果。

无论如何,你到底是如何捕捉动画的结尾的,你能展示你使用的代码吗?

另一个问题是,为什么您需要立即正确?如果您明确设置选择器,那么您已经确切知道设置了什么值,那么为什么还要再问一次呢?

于 2012-03-13T08:49:05.813 回答