Allowing user to select a UIPickerView row by tapping

camilo picture camilo · Mar 8, 2010 · Viewed 14.6k times · Source

I'm trying to use a UIPicker View with a behavior somehow different of what's usually seen in iPhone code examples.

What I want to do is to allow users to scroll through the picker contents, but not to select a picker's row automatically (using the "didSelectRow" method from picker's delegate). Instead, I want to allow the user to touch the center row of the picker, which gets highlighted, and becomes the selection.

Is there any way to achieve this?

Thanks in advance.

Answer

Martin Linklater picture Martin Linklater · Oct 28, 2011

Add a gesture recogniser to the UIPickerView which triggers a target method in your object:

myGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickerTapped:)];
[myPicker addGestureRecognizer:myGR];

// target method

-(void)pickerTapped:(id)sender
{
// your code
}