我正在使用以下代码向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];
}
}
上面的代码适用于显示和滚动,但是当我点击标签滚动时,它什么都不做。如果我点击标签外面,就像拾取器的角落一样,滚轮会转向选择它。
任何建议都将不胜感激。
杆
答案 0 :(得分:5)
将customView的userInteractionEnabled
属性设置为NO
。似乎如果将其设置为YES,则自定义视图拦截触摸和选择器无法滚动到所触发的行。