UIPicker crashes app if i spin one component at the same time as another
I have a picker with three components.
The first two components are dependent on the last.
So it could be:
- | 5 | M (The lines represent the different columns) or 1" | 5" | FT
If I am moving the second or first column and before they stop spinning I move the third column from from FT to M or visa versa and then while that is still moving it crashes the app.
I know this is happening because in pickerView:didSelectRow:inComponent:
delegate method for the UIPicker I am performing a calculation based on the final value of the third column i.e M or FT.
SO, IN A NUTSHELL
It is performing the pickerView:didSelectRow:inComponent:
on the third column before the first column even though the users touched them in the opposite order.
Is there any way to resolve this?
Possibly make it so that if a component is stil开发者_高级运维l spinning the user is unable to move another component?
Any help is highly appreciated
Thanks
Tom
I think that while a component is spinning it has no selected value so it never calls pickerView:didSelectRow:inComponent:
Once it does stop spinning it does send the message to the delegate. The first component to stop spinning sends first, not the first component touched. This is why your third column calls the method before the first two even though it is touched last.
I suspect the crash is caused by trying to perform an operation using the nil selected row value of a moving component. If so, you can avoid the crash by testing that each components selected value is not nil before performing the operation. If the components are still spinning then you should skip the operation until they stop.
I don't think it is possible freeze components.
You can "freeze" your components by placing clear UIViews over top of them. As soon as one component starts spinning you can show the clear views to prevent user interaction on the other components.
This should stop this issue from occurring.
精彩评论