views:

26

answers:

1

I'm using the following code to add a label and a view to a UIPickerView.

- (UIView *)pickerView:(UIPickerView *)pickerView
        viewForRow:(NSInteger)row
      forComponent:(NSInteger)component
       reusingView:(UIView *)view {


CustomPickerView *customView = [[CustomPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 180, 32)];

CustomPickerLabel *pickerLabelLeft = [[CustomPickerLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 80, 32)];
[pickerLabelLeft setTextAlignment:UITextAlignmentRight];
pickerLabelLeft.backgroundColor = [UIColor clearColor];
[pickerLabelLeft setText:@"1234"];

[customView addSubview:pickerLabelLeft];

return customView;

}

The reason I'm using a view is because I want to add two labels to this view and display them in the picker. The CustomPickerView and CustomPickerLabel classes contain the following code, each:

- (void)didMoveToSuperview { if ([[self superview] respondsToSelector:@selector(setShowSelection:)]) { [[self superview] performSelector:@selector(setShowSelection:) withObject:NO]; } }

the above code works fine for display and scrolling, but when I click on the label to scroll, it does nothing. If I click just outside the label, as in the corners of the picker, the wheel turns to the selection as it should.

Any suggestions would be appreciated.

Rod

A: 

Set your customView's userInteractionEnabled property to NO. It seems that if it is set to YES then custom view intercept touches and picker can't scroll to the tapped row.

Vladimir
Man, thank you SO MUCH! I kept trying to set the label's and view's userInteractionEnabled to YES (intuitively) and a combination of the two, but never tried NO (figured that was default).
Rod