UIPickerView getting stuck between rows?
I've noticed a problem when using UIPickerView, and I'm wondering if anyone has ever encountered it before: Sometimes when scrolling one of the wheels, it gets stuck between two rows (after touches have ended), and just stays like that indefinitely. Dragging the wheel again slightly and releasing always corrects the problem, but regardless, I'm puzzled as to why this is happening in the first place. It occurs when testing both in the simulator and on an actual device.
The problem isn't so much the annoyanc开发者_如何学运维e of having to re-adjust the wheel when it gets stuck, but rather that sometimes it gets stuck when it's extremely close to selecting a row (but hasn't actually selected it) which can give the user the impression that they have chosen a given row, when really they haven't.
Has this happened to anyone else, and if so, is there a way to fix it?
Thanks,
Chris
Still haven't figured out a good way to solve this... the best solution I've been able to think of is including the following line in the pickerView:didSelectRow:inComponent:
method:
[pickerView selectRow:[pickerView selectedRowInComponent:0] inComponent:0 animated:YES];
This will make the specified component roll back onto the correct row, ensuring that the user is always seeing an accurate representation of what's selected, however it sometimes looks strange when you think the component is going to stop on a certain row, only to see it animate backwards in the opposite direction before stopping.
I had an issue very similar to this. The UIPickerView would scroll and stop between rows. Normally this view will not stop between rows it will scroll itself to the next row even if you try to stop it in-between two items. I have many apps that did not show the problem even though they used the same code to instantiate UIPickerView.
After much investigation I found my problem was over usage of CPU. My application is an OpenGL game, so I have a game loop running as fast as possible to update the frames. Admittedly my game was CPU bound and not achieving a full frame rate. I was leaving the game running in the background while the pickerView popped up to allow the user to make a selection. This seems to have left no CPU for the UIPickerView to detect it had stopped between rows and pull itself to the nearest row.
My simple solution is to pause the game while the picker view is up.
I see this answer is a year late, but it took me a while to figure out so hope it helps someone.
I think I've figured it out. When the view that you are using the UIPickerView in loads, you need to set the pickers delegate, like this:
picker.delegate = self;
That should fix the issue and cause the picker to automatically center on a value rather than floating between rows.
you should check frames of the subviews in pickerview delegate method (pickerView:viewForRow:forComponent:reusingView:). frames height should should not exceed from content view's height.
精彩评论