2011-07-18 136 views
0

我有一個橫向視圖和一個肖像視圖,作爲包裝視圖的子視圖加載主視圖。橫向視圖和縱向視圖都具有鏈接到它們的UIPickerView對象。在我的源文件中,我將它們全部作爲屬性,並且還爲景觀和肖像拾取器提供了包裝。他們被定義爲UIPickerView不返回正確的數據

@property (nonatomic, retain, readonly) IBOutlet UIPickerView *pickerTown; 
@property (nonatomic, retain, readonly) IBOutlet UIPickerView *pickerType; 
@property (nonatomic, retain, readonly) IBOutlet UIDatePicker *pickerFrom; 
@property (nonatomic, retain, readonly) IBOutlet UIDatePicker *pickerTo; 

@property (nonatomic, retain) IBOutlet UIPickerView *landscapePickerTown; 
@property (nonatomic, retain) IBOutlet UIPickerView *landscapePickerType; 
@property (nonatomic, retain) IBOutlet UIDatePicker *landscapePickerFrom; 
@property (nonatomic, retain) IBOutlet UIDatePicker *landscapePickerTo; 

@property (nonatomic, retain) IBOutlet UIPickerView *portraitPickerTown; 
@property (nonatomic, retain) IBOutlet UIPickerView *portraitPickerType; 
@property (nonatomic, retain) IBOutlet UIDatePicker *portraitPickerFrom; 
@property (nonatomic, retain) IBOutlet UIDatePicker *portraitPickerTo; 

和每個只讀包裝的我有

- (UIPickerView *) pickerTown 
{ 
    if(self.landscapeView.superview) 
    { 
     return landscapePickerTown; 
    }else 
    { 
     return portraitPickerTown; 
    } 
} 

但是,當我在肖像或風景,我試着例如說

myHelper.selectedTown = [myHelper.towns objectAtIndex:[pickerTown selectedRowInComponent:0]]; 

我沒有得到選定的值,而只是數組中的第一個值。

的數據被添加如下:

if(pickerView == landscapePickerType || pickerView == portraitPickerType) { 
    return [myHelper.types objectAtIndex:row]; 
}else if(pickerView == landscapePickerTown || pickerView == portraitPickerTown){ 
    return [myHelper.towns objectAtIndex:row]; 
}else 
{ 
    return @""; 
} 

和數組:

myHelper = [Helper sharedManager]; 
[myHelper.types addObject:@"None"]; 
[myHelper.types addObject:@"Food & Wine"]; 
[myHelper.types addObject:@"Test"]; 
[myHelper.towns addObject:@"None"]; 
[myHelper.towns addObject:@"Vanderbijlpark"]; 
[myHelper.towns addObject:@"Test"]; 

什麼我錯在這裏做什麼?

回答

1

如果您只獲取第一個元素,則表明[pickerTown selectedRowInComponent:0]正在計算總是零,只有在pickerTownnil時纔會發生這種情況。這再次很可能是由於插座沒有連接。

但在這種情況下,我認爲你直接訪問實例變量,而不是方法返回的值。如果您使用@synthesize作爲pickerTown,請使用@dynamic。並將該語句更改爲[self.pickerTown selectedRowInComponent:0]以訪問getter的值。

+0

作品謝謝 – Armand