views:

224

answers:

2

Hi All

I have a picker with three components.

The first two components are dependent on the last.

So it could be:

  1. | 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 still spinning the user is unable to move another component?

Any help is highly appreciated

Thanks

Tom

+2  A: 

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.

TechZen
This does seem to be the case... therefore is it possible to pause halfway through a method for a set interval and then continue the operation?
Tom G
If I understand what you're doing, the simplest thing to do would be to test whether all columns have selected values and only proceed with the calculation if they do. Since all 3 columns call the same didSelectRow: method, each can trigger the calculation when it is the last component to stop moving. You just need enough condition checking in the code.
TechZen
That was the key...after using break points i realised that i did not have enough conditon handling in place... thanks for your help :)
Tom G
+2  A: 

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.

jessecurry