Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 annoyance 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

like image 274
Chris B. Avatar asked Oct 24 '22 14:10

Chris B.


2 Answers

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.

like image 83
chris b Avatar answered Nov 04 '22 19:11

chris b


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.

like image 23
Jacquin Avatar answered Nov 04 '22 20:11

Jacquin