2014-07-19 89 views
0

我正在開發一個使用uipickerview的三個文本框的視圖。 pickerview是相同的,但內容是動態的,取決於用戶正在編輯的文本字段。UIPickerview iOS6 vs iOS7 viewForRow

如果我在iOS7設備上運行應用程序沒有問題,但是如果我在iOS6設備上運行它,當我滾動選擇器視圖時,我看到舊值並且沒有顯示任何正確的值。有什麼事?

這是源代碼

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger)component reusingView:(UIView *)view 
{ 
UIView *pickerCustomView = (id)view; 
//pickerCustomView = [[UIView alloc] init]; 
UILabel *pickerViewLabel; 
UIImageView *pickerImageView; 
NSString *testo; 
UIImage *immagine; 


if (mieiCalc.isEditing) { 

    NSString *imgRuolo = 
    [NSString stringWithFormat:@"%@%@", 
    [[mieiArray objectAtIndex:row] objectForKey:@"RUOLO"], 
    @".png"]; 
    testo = [[mieiArray objectAtIndex:row] objectForKey:@"CALCIATORE"]; 

    testo = 
    [NSString stringWithFormat:@"%@%@%@%@", 
    [[mieiArray objectAtIndex:row] objectForKey:@"CALCIATORE"], 
    @" (", 
    [[mieiArray objectAtIndex:row] objectForKey:@"COSTO"], 
    @")" 
    ]; 


    immagine = [variabiliGlobali imageResize:imgRuolo larghezza:30]; 
} 
else if (squadreCalc.isEditing) { 
    testo = [tutteSquadreArray objectAtIndex:row]; 
    immagine = [variabiliGlobali imageResize:[variabiliGlobali getImgSquadra:testo] larghezza:30]; 
} 
else { 
    testo = 
    [NSString stringWithFormat:@"%@%@%@%@", 
    [[altriArray objectAtIndex:row] objectForKey:@"CALCIATORE"], 
    @" (", 
    [[altriArray objectAtIndex:row] objectForKey:@"COSTO"], 
    @")" 
    ]; 
    immagine = [variabiliGlobali imageResize:[variabiliGlobali getImgSquadra:[[altriArray objectAtIndex:row] objectForKey:@"SQUADRA"]] larghezza:30]; 

} 

if (!pickerCustomView) { 
    pickerCustomView= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 

    if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { 
     pickerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 10, 30, 30)]; 
     pickerViewLabel= [[UILabel alloc] initWithFrame:CGRectMake(50, 10, 270, 30)]; 
    } 
    else { 
     pickerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 30, 30)]; 
     pickerViewLabel= [[UILabel alloc] initWithFrame:CGRectMake(50, 10, 270, 30)]; 

    } 
    pickerViewLabel.textColor = [UIColor blackColor]; 
    // the values for x and y are specific for my example 
    [pickerCustomView addSubview:pickerImageView]; 
    [pickerCustomView addSubview:pickerViewLabel]; 
} 

pickerImageView.image = immagine; 
pickerViewLabel.backgroundColor = [UIColor clearColor]; 
pickerViewLabel.text = testo; // where therapyTypes[row] is a specific example from my code 
//pickerViewLabel.font = [UIFont fontWithName:@"ChalkboardSE-Regular" size:20]; 

[pickerViewLabel setFont:MYFONT(20)]; 

return pickerCustomView; 
} 
+0

您沒有提供幫助您所需的詳細信息。您似乎根據值mieiCalc.isEditing和squadreCalc.isEditing確定要返回哪個視圖。但是你不告訴我們這些是什麼或者它們是如何設置的。您不會告訴我們如何根據所選文本字段設置選取器視圖或重新載入視圖。在發佈這個問題之前,您應該花費大量時間使用調試器來追蹤問題。你到底做了什麼來確定問題? – rmaddy

+1

順便說一句 - iOS 8即將推出(很可能在9月份)。此時,您應該編寫應用程序以支持iOS 7和iOS 8.實際上,沒有理由在此時編寫支持iOS 6的應用程序。 – rmaddy

回答

-1

我以這種方式解決了。我已添加此源代碼

if (pickerImageView == nil) { 
    pickerImageView = view.subviews[0]; 

} 

if (pickerViewLabel == nil) { 

    pickerViewLabel = view.subviews[1]; 
} 

pickerview的視圖被重用,因此標籤和UIImageLabel未刷新。

+0

它不起作用 – Tendulkar