2013-08-23 103 views
0

我有兩個選擇器的視圖,並且我使用...viewForRow...來修改顯示在選取器內的文本的字體。但是,我的其中一個選取器顯示爲空,但如果我滾動選取器,則這些值將出現在其指定的textField中。另一個選擇器看起來非常好。我想知道爲什麼一個選擇器顯示爲空?UIPickerView顯示爲空

注意顯示爲空的選取器有兩個組件。這是一個信用卡到期日期選擇器,因此每個月只有一個組件,而且每年只有一個組件。

下面是...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; 
} 

任何提示,將不勝感激。

回答

0

想通了。這是因爲,選取器有兩個組件,我通過pickerLabel製作的標籤對於雙組件選取器來說太大了。所以,我不得不將CGRect的寬度除以2,並且它工作。