UIPickerView具有自定义视图和标签不滚动

时间:2010-10-14 06:55:01

标签: iphone objective-c uipickerview

我正在使用以下代码向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;

}

我使用视图的原因是因为我想在此视图中添加两个标签并将其显示在选择器中。 CustomPickerView和CustomPickerLabel类包含以下代码:

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

上面的代码适用于显示和滚动,但是当我点击标签滚动时,它什么都不做。如果我点击标签外面,就像拾取器的角落一样,滚轮会转向选择它。

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:5)

将customView的userInteractionEnabled属性设置为NO。似乎如果将其设置为YES,则自定义视图拦截触摸和选择器无法滚动到所触发的行。