我使用下面的代碼添加標籤和視圖到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]; } }
上面的代碼工作正常顯示和滾動,但是當我在標籤上點擊,滾動,它什麼都不做。如果我在標籤外面單擊,就像在選取器的角落中一樣,輪子會根據需要轉向選擇。
任何建議,將不勝感激。
杆
男人,謝謝你這麼多!我一直試圖將標籤和視圖的userInteractionEnabled設置爲YES(直觀)和兩者的組合,但從未嘗試過NO(認爲是默認設置)。 – Rod 2010-10-14 07:18:23