如何恢复我的选择器值

发布于 2024-10-11 02:01:45 字数 2735 浏览 4 评论 0原文

华氏度是 NSObjectWakingTemperatureUIViewController。我正在将选择器值从华氏温度更新为 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];
    }

Fahrenheit is NSObject and WakingTemperature is UIViewController. I am updating picker value from Fahrenheit to WakingTemperature(Basically two nsobject for Fahrenheit and Celsius to toggle, i put code for Fahrenheit).

Now I have problem restore my picker value But not happening . here is what i tried
in updatelable, please help me.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

埋葬我深情 2024-10-18 02:01:45

首先,为什么要在 updateLabel 结束时重新加载 pickerview ?

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

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

链接文本

First of all, why do you reload your pickerview at the end of updateLabel?

to initialize your picker to a specific value xxx, you would use

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

There is a good tutorial for an infinite picker on link text

眼眸里的那抹悲凉 2024-10-18 02:01:45

updateLabel 中删除

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

didSelectRow 方法中完成的更改

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

Removed from updateLabel

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

Changes done in didSelectRow method

Appdelegate.pickerRowCompzero=[pickerView selectedRowInComponent:0];
Appdelegate.pickerRowCompone= [pickerView selectedRowInComponent:1];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文