2011-01-10 12 views
0

Fahrenheit ist NSObject und WakingTemperature ist UIViewController. Ich aktualisiere Picker Wert von Fahrenheit zu WakingTemperature (Grundsätzlich zwei nsobject für Fahrenheit und Celsius zu schalten, ich legte Code für Fahrenheit).So stellen Sie meinen Auswahlwert wieder her

Jetzt habe ich Problem, meinen Picker Wert wiederherzustellen, aber nicht passiert. hier ist, was ich versuchte in updateable, bitte hilf mir.

@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

Was meinen Sie mit "Jetzt habe ich Problem, meinen Picker Wert wiederherzustellen"? Und welchen Code der Methode hast du gepostet (unterer Teil deines Eintrags)? – Axel

+0

bearbeiten, ich muss meinen zuletzt ausgewählten Auswahlwert speichern, aber immer den Standardwert. – SOF

Antwort

0

Entfernt von updateLabel

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

Änderungen verwenden würden, getan in didSelectRow methode

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

Zuerst, warum laden Sie Ihre Pickerview am Ende von updateLabel neu?

Ihre Kommissionierer auf einen bestimmten Wert xxx zu initialisieren, Sie

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

Es ist ein gutes Tutorial für eine unendliche Picker auf link text

+0

Entschuldigung, ich habe dein Problem immer noch nicht verstanden. Wann funktioniert das Nachladen nicht? Und wann ist es? - Ihr Problem ist, dass Sie zwei Picker haben und von Fahrenheit in Celsius umrechnen wollen und umgekehrt? Auf welche Umschaltoption verweisen Sie? – Axel

Verwandte Themen