how to restore my picker value
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"];
Arr开发者_Python百科ayofbothTempfractional = [[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];
}
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
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];
精彩评论