View Full Version : UIPickerView - Constant rotation - help!

Aug 24, 2008, 04:06 PM
Ive just started yesterday trying to build an app with the iPhone SDK and Ive run into a problem with the UIPickerView - if anyone could help it would be much appreciated!

I have created a UIPickerView that has the values 0-59 that the user can select from. I want to the picker to roll through all the values and loop - AKA the stopwatch application.

The problem I am having that is when you scroll down to 59 the PickerRoll stops and to get back to 0 you have to scroll all the way back up again...

Ive been searching online for a way to solve it and I cant find anything - anyone have any ideas?

Aug 27, 2008, 03:51 PM
Im still really stuck with this one - but I now know that is is possible to do what I am trying to do as I have seen this implemented in the UrbanSpoon app.

Does anyone have any idea how you would replicate what has been done in the Urban spoon app?

How did they manage to make a picker view that can rotate through the values in its DataSource?

If anyone could offer me a glimmer of hope it would be great - this is the 4th time Ive posted this question in various forums and nobody has replied to any of them!

Maybe someone could just reply and wish me luck?? :)

Aug 27, 2008, 03:58 PM
Good luck!

I'll play around with stuff and see what I can find.

Aug 27, 2008, 04:14 PM
Here's something that works great!

Basic model: an array of n objects ("rows" in this example), one for each row in your picker view.

Instead of saying that your picker view has n rows, say it has 3n rows.

When it asks for the title of a row, give it:
return [rows objectAtIndex:(row % [rows count])];

When it says the user didSelectRow:inComponent:, use something like this:

//we want the selection to always be in the SECOND set (so that it looks like it has stuff before and after)
if (row < [rows count] || row >= (2 * [rows count]) ) {
row = row % [rows count];
row += [rows count];
[pickerView selectRow:row inComponent:component animated:NO];

The problem is that it starts off at the top, instead of in the second set. You can easily manipulate that in a viewDidLoad or init method or something.

Getting around the delay of getting to the end is fixable by instead of using 3n rows, use 7n. Again, you'd always want to redirect the user back to the middle set, but 7n rows would allow them to flick really fast, but not fast enough to get to the top.

Edit: 7n can still be gotten around, but that's the general idea.
Edit again: 49n works great! :D ;)
Edit yet again: I should point out that you don't need a large number of iterations if you have a large number of items in your "rows" array. I only tested 5, so obviously I was going to need a lot of iterations. If you have 150 items in your array, you could easily get by with 3 iterations.

Good luck,


Oct 3, 2008, 09:33 AM
Hi Guys,

I am using UIPickerView class for creating the picker component.
I am able to create three picker component and also able to spin it but problem is that wheel is spinning from 0th row to nth row.

I am stuck trying to find a way to make the wheel turn all the way round - when the user scrolls down from 0-n I want it to loop back to 0 again so that it looks continuous - but I just cant figure it out..

Is there anybody has done such a kind of implementation i.e. making UIPickerView circular?

thanks in advanced.


Oct 3, 2008, 09:39 AM
Please learn to use the search facility. There is a pre-existing thread asking this exact question. Please see this thread (http://forums.macrumors.com/showthread.php?t=550262&highlight=UIPickerView)

Mar 10, 2009, 12:43 PM
I recently posted some code that does this to my blog (http://beardedpony.wordpress.com/2009/03/03/howd-you-get-that-cool-urban-spoon-type-animation/).

Leave a comment if it helps!!