2011-01-10 45 views
0

華氏はNSObjectWakingTemperatureUIViewControllerです。私は、華氏からピッカー値をWakingTemperatureに更新しています(基本的には、華氏と摂氏の2つの値がトグルするために、華氏のコードを入れます)。ピッカー値を復元する方法

今私はピッカーの値を復元するのに問題はありますが、起こっていません。ここでは私が試みたのは で、updatelableで助けてください。

@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

「今、ピッカーの価値を回復するのに問題がありますか?」とはどういう意味ですか? whochメソッドのコードはあなたの投稿(あなたのリストの下の部分)でしたか? – Axel

+0

編集、最後に選択したピッカー値を保存する必要がありますが、常にデフォルト値になります。 – SOF

答えて

0

上無限ピッカーのための優れたチュートリアルがありますdone in didSelectRow

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

まず、updateLabelの最後にピッカービューをリロードするのはなぜですか?特定の値をXXXにごピッカーを初期化する

は、あなたが

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

を使用することになりupdateLabel

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

変更から削除link text

+0

申し訳ありませんが、私はまだあなたの問題を理解していないと思います。リロードしないのはいつですか?それはいつですか? - あなたの問題は、あなたが2人のピッカを持っていて、華氏から摂氏に変換したいのですか?あなたが参照するトグルオプションは何ですか? – Axel

関連する問題