如何恢复我的选择器值
华氏度是 NSObject
,WakingTemperature
是 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];
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,为什么要在 updateLabel 结束时重新加载 pickerview ?
要将选择器初始化为特定值 xxx,您可以使用
链接文本
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
There is a good tutorial for an infinite picker on link text
从
updateLabel
中删除在
didSelectRow
方法中完成的更改Removed from
updateLabel
Changes done in
didSelectRow
method