我有一个带有两个选择器的视图,我正在使用...viewForRow...
它来修改出现在选择器内的文本的字体。但是,我的选择器之一显示为空,但如果我滚动选择器,值将出现在其指定的文本字段中。另一个选择器看起来非常好。我想知道为什么其中一个选择器显示为空?
请注意,显示为空的选择器有两个组件。它是一个信用卡到期日期选择器,因此有一个用于月份的组件和一个用于年份的组件。
这是该...viewForRow...
方法的代码:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *pickerLabel = (UILabel *)view;
if (pickerLabel == nil)
{
//label size
CGRect frame = CGRectMake(0.0, 0.0, 280, 30);
pickerLabel = [[UILabel alloc] initWithFrame:frame];
[pickerLabel setTextAlignment:UITextAlignmentLeft];
[pickerLabel setBackgroundColor:[UIColor clearColor]];
[pickerLabel setFont:[UIFont fontWithName:@"Helvetica" size:11.0]];
}
if ([pickerView isEqual:pickerExpiration])
{
if (component == 0)
{
[pickerLabel setText:[NSString stringWithFormat:@"%@", [monthsList objectAtIndex:row]]];
}
[pickerLabel setText:[NSString stringWithFormat:@"%@", [yearsList objectAtIndex:row]]];
return pickerLabel;
}
billingAddress = [addresses objectAtIndex:row];
[pickerLabel setText:[NSString stringWithFormat:@"%@ %@", billingAddress.addressName, billingAddress.fullAddressText]];
return pickerLabel;
}
任何提示将非常感谢。