Rod*_*Rod 3 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;
Run Code Online (Sandbox Code Playgroud)
}
我使用视图的原因是因为我想在此视图中添加两个标签并将其显示在选择器中.CustomPickerView和CustomPickerLabel类包含以下代码,每个代码:
- (void)didMoveToSuperview
{
if ([[self superview] respondsToSelector:@selector(setShowSelection:)])
{
[[self superview] performSelector:@selector(setShowSelection:) withObject:NO];
}
}
上面的代码适用于显示和滚动,但是当我点击标签滚动时,它什么都不做.如果我在标签外面点击,就像拾取器的角落一样,滚轮会转向选择它应该的位置.
任何建议,将不胜感激.
竿