2011-01-10 55 views
0

華氏溫標是NSObjectWakingTemperatureUIViewController。我正在更新從華氏溫度選擇器值WakingTemperature(基本上兩個華氏溫度和攝氏溫度切換,我把代碼華氏溫度)。如何恢復我的選取器值

現在我有問題恢復我的選擇器值但沒有發生。這裏是我嘗試 可更新,請幫助我。

@interface FertilityAppAppDelegate 
---------------------------------- 
     NSInteger pickerRowCompzero; 
     NSInteger pickerRowCompone; 
     float valueConv; 

     @property (nonatomic) NSInteger pickerRowCompzero; 
     @property (nonatomic) NSInteger pickerRowCompone; 
     @property (nonatomic) float valueConv; 

@implementation FertilityAppAppDelegate 
--------------------------------------- 
     @synthesize pickerRowCompzero,pickerRowCompone; 
     @synthesize valueConv; 

@implementation Fahrenheit 
-------------------------- 
    - (id)init 
{   
/* initialize data-arrays here */ 

ArrayofTempIntegerofCelsius = [[NSMutableArray alloc] init]; 

[ArrayofTempIntegerofCelsius addObject:@"36"]; 
[ArrayofTempIntegerofCelsius addObject:@"37"]; 
[ArrayofTempIntegerofCelsius addObject:@"38"]; 
[ArrayofTempIntegerofCelsius addObject:@"39"]; 
[ArrayofTempIntegerofCelsius addObject:@"40"]; 
[ArrayofTempIntegerofCelsius addObject:@"41"]; 

ArrayofbothTempfractional = [[NSMutableArray alloc] init]; 

[ArrayofbothTempfractional addObject:@".0"]; 
[ArrayofbothTempfractional addObject:@".1"]; 
[ArrayofbothTempfractional addObject:@".2"]; 
[ArrayofbothTempfractional addObject:@".3"]; 
[ArrayofbothTempfractional addObject:@".4"]; 
[ArrayofbothTempfractional addObject:@".5"]; 
[ArrayofbothTempfractional addObject:@".6"]; 
[ArrayofbothTempfractional addObject:@".7"]; 
[ArrayofbothTempfractional addObject:@".8"]; 
[ArrayofbothTempfractional addObject:@".9"]; 

Appdelegate = (FertilityAppAppDelegate*)[[UIApplication sharedApplication] delegate]; 


return self;    
} 



    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
    { 
     [self updateLabel]; 
    } 

    -(void) updateLabel 
    { 
     Appdelegate.pickerRowCompzero=[pickerView selectedRowInComponent:0]; 
    Appdelegate.pickerRowCompone=[pickerView selectedRowInComponent:1]; 

    NSString *integer = [ArrayofTempIntegerofFahrenheit objectAtIndex:Appdelegate.pickerRowCompzero]; 
    NSString *fraction = [ArrayofbothTempfractional  objectAtIndex: Appdelegate.pickerRowCompone]; 

    NSString *fahrenheit = [NSString stringWithFormat:@"%@%@",integer,fraction]; 
    Appdelegate.valueConv = [fahrenheit floatValue]; 

    label.text=[NSString stringWithFormat:@"%.1f",Appdelegate.valueConv]; 
    NSLog(@"float:%f ",Appdelegate.valueConv); 

edit // [pickerView reloadAllComponents]; 
    } 
+0

你是什麼意思「現在我有問題恢復我的選擇器值」?您發佈的是誰的方法代碼(列表的下半部分)? – Axel 2011-01-10 08:37:19

+0

編輯,我需要保存我上次選擇的選取器值,但總是默認值。 – SOF 2011-01-10 09:41:54

回答

0

updateLabel

Appdelegate.pickerRowCompzero=[pickerView selectedRowInComponent:0]; 
Appdelegate.pickerRowCompone=[pickerView selectedRowInComponent:1]; 

更改刪除在didSelectRow方法中完成

Appdelegate.pickerRowCompzero=[pickerView selectedRowInComponent:0]; 
Appdelegate.pickerRowCompone= [pickerView selectedRowInComponent:1]; 
0

首先,爲什麼要在updateLabel結尾重新加載pickerview?

您選擇器初始化爲特定值的XXX,你可以使用

[pickerView selectRow:xxx inComponent:0 animated:FALSE]; // set default values 

有一個很好的教程無限選擇器上link text