华氏温度为NSObject
,WakingTemperature
为UIViewController
。我正在更新从华氏度到WakingTemperature
的选择器值(基本上是华氏和摄氏的两个对象来切换,我为华氏放置代码)。
现在我有问题恢复我的选择器值但是没有发生。这是我试过的 在可更新,请帮助我。
@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 :(得分:0)
首先,为什么要在updateLabel结束时重新加载pickerview?
将您的选择器初始化为特定值xxx,您可以使用
[pickerView selectRow:xxx inComponent:0 animated:FALSE]; // set default values
上有一个关于无限选择器的好教程
答案 1 :(得分:0)
从updateLabel
Appdelegate.pickerRowCompzero=[pickerView selectedRowInComponent:0];
Appdelegate.pickerRowCompone=[pickerView selectedRowInComponent:1];
在didSelectRow
方法
Appdelegate.pickerRowCompzero=[pickerView selectedRowInComponent:0];
Appdelegate.pickerRowCompone= [pickerView selectedRowInComponent:1];