I have a UIActionSheet containing a picker and a UIToolbar. On the UIToolBar there is a save button. However, some of my users reported pressing the save button before the UIPickerView stops spinning thus only retrieving the initial value (before spinning).
Is there a way to get the currently selected item of the UIPickerView once the user taps save or get feedback of the active selected item while it's spinning?
Thanks
This might be a "hack," but it works. My case is slightly different. I'm using one
UIPicker
, but can change what object it is manipulation.My issue was that you could select one object, spin the picker, and while it is finishing its spin, select a different object. What ended up happening was the new object was getting the final value of that spin, rather than it being ignored.
What I did what when setting up the
UIPicker
I'd give it a uniquetag
based on the object that it was supposed to update.Then when it finishes its spin, I check to make sure that tag lines up still.
I'm not sure how it is functioning on Apple's side, but this was enough to make it work for me.
As a side note, and I'm not sure if this matters, but my
UIPicker
is in aUITableViewCell
but since it is a reusable cell and because I was having the issues that I was, I assume the UIPicker is the same when it is moved from one position to another (as there is only one on screen at a time).Even if they dismiss the picker while it's still spinning, the picker will still call the delegate with the final selected row once it stops, even if it isn't visible. Assuming you haven't deallocated it yet, you can set the delegate receiver to check if the picker is visible, and if it isn't, save the selected value.
I do this assuming it's clear the user isn't scrolling to a random value - usually when they scroll and dismiss without waiting for it to settle, it means they scrolled to either the very top or very bottom of the list. I'd say you can safely use the result of the delegate in these two cases.
I had the same problem... I fixed it by simply adding the following code line on the method that closes or selects the picker value.
I don't think this is a problem you're going to be able to solve with
UIPickerView
by itself.There is no way to now which row is selected without the animation stopping (and thus the picker view selecting the row it stopped on). The only way would be to tell the picker which row to stop on, by using the
selectRow:inComponent:animated:
but how will you know which row that is? You don't know because the picker is spinning...I think this is just a limitation of the
UIPickerView
and Apple would likely describe it as expected behaviour.Just found solution, which works for my case. I don't need that last update event, generated when picker stops spinning after user dismissed it. So this method stops scrolling and don't causes new update selection event. Seems you'll going to check if selections are ok in picker after this (I don't care, I reselect values when I show picker).