Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何恢复我的选择器值_Iphone_Ios_Uipickerview - Fatal编程技术网

Iphone 如何恢复我的选择器值

Iphone 如何恢复我的选择器值,iphone,ios,uipickerview,Iphone,Ios,Uipickerview,华氏温度是NSObject,wakingtimeter是UIViewController。我正在将选择器值从华氏度更新为WakingTemperature(基本上是两个nsobject,用于切换华氏度和摄氏度,我将代码用于华氏度) 现在我有问题恢复我的选择器值,但没有发生。这是我试过的 在更新中,请帮助我 @interface FertilityAppAppDelegate ---------------------------------- NSInteger pickerRo

华氏温度是
NSObject
wakingtimeter
UIViewController
。我正在将选择器值从华氏度更新为
WakingTemperature
(基本上是两个nsobject,用于切换华氏度和摄氏度,我将代码用于华氏度)

现在我有问题恢复我的选择器值,但没有发生。这是我试过的 在更新中,请帮助我

@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];
    }

首先,为什么要在updateLabel末尾重新加载pickerview

要将选择器初始化为特定值xxx,可以使用

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

updateLabel

Appdelegate.pickerRowCompzero=[pickerView selectedRowInComponent:0];
Appdelegate.pickerRowCompone=[pickerView selectedRowInComponent:1];
didSelectRow
方法中进行的更改

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

“现在我无法恢复我的选择器值”是什么意思?您发布的是哪种方法的代码(列表的下半部分)?编辑,我需要保存上次选择的选择器值,但始终是默认值。抱歉,我想我仍然不理解您的问题。什么时候重新加载不起作用?什么时候开始你的问题是你有两个选择器,你想把华氏温度转换成摄氏温度,反之亦然?您所指的切换选项是什么?