2011-01-10 16 views
0

화씨는 NSObject이고 WakingTemperatureUIViewController입니다. 나는 화씨에서 피커 값을 WakingTemperature (기본적으로 화씨와 섭씨는 두 개를 토글하여 토글합니다. 화씨는 코드를 넣습니다)로 업데이트합니다.피커 값을 복원하는 방법

이제 피커 값을 복원하는 데 문제가 있습니다.하지만 그런 일은 일어나지 않습니다. 여기에 내가 시도한 것입니다 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

에 무한 선택기에 대한 좋은 튜토리얼이 있습니다

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

사용하는 것이 특정 값 XXX에 선택기를 초기화 done in didSelectRow

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

첫째, 왜 updateLabel의 끝에서 당신의 pickerview를 다시로드합니까?

, 당신은 updateLabel

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

변경에서 제거 link text

+0

죄송합니다. 아직 귀하의 문제를 이해하지 못했습니다. 재 장전은 언제 작동하지 않습니까? 언제 그럴까요? - 문제는 두 명의 선택기가 있고 화씨에서 섭씨로 변환하고 그 반대의 경우입니다. 당신이 참조하는 토글 옵션은 무엇입니까? – Axel

관련 문제