views:

219

answers:

1

Hey,

I have a UIPickerView with two components. It works fine when the user scrolls each component until it reaches the desired value. But I want it to behave like the picker in the calendar or the clock apps. Meaning: When the user presses a certain value in one of the components, I want that component to automatically turn that row to be the selected row (so the user doesn't always have to scroll, he/she can also simply select the value they want).

Does anyone know how to do that?

Thank you,

~Chonch

A: 

It is standard picker behaviour and it should work so automatically.

If your picker does not select tapped row automatically try to set userInteractionEnabled property to NO for the view you return from viewForRow: method in picker data source.

Vladimir
I use UIView with a UILabel inside it as the return value for viewForRow. I tried to add userInteractionEnabled for both the UILabel and the UIView but it doesn't seem to help.Can you think of any other option?
Chonch
Could you post your viewForRow: method?
Vladimir
if (component == 0) { Style *curStyle = [self.styleArray objectAtIndex:row]; // Create the view for the current part CGRect frame = CGRectMake(0, 0, 120, 46); UIView *view = [[UIView alloc] initWithFrame:frame]; // Add the part name frame = CGRectMake(10, 0, 110, 46); UILabel *lbl = [[UILabel alloc] initWithFrame:frame]; lbl.text = curStyle.styleName; lbl.backgroundColor = [UIColor clearColor]; [view addSubview:lbl]; [lbl release]; view.userInteractionEnabled = YES; return view; } else return [self.partsArray objectAtIndex:row];
Chonch
So sorry, I had similar problem some time before and posted solution from memory, but remembered general approach and completely confused the details. See updated answer.
Vladimir
Thank you very very much... It works... :-)
Chonch