I'm creating an app that uses UIPickerView. When I run the app, if I don't manually move the picker, the default value is "null" (even though is SHOWS that a value is selected).
I've tried running [picker selectRow:0 inComponent:0 animated:YES]
within the viewDidAppear
method, but the value for the picker is still "null".
Below is a screen shot of the picker as it is initialized, BEFORE being moved manually, but AFTER the method mentioned above has been run:
And the output if you select "GO!" without manually moving the picker
Any thoughts? This is the same question as can be found in this thread, which has yet to have been answered.
Thanks much.
EDIT:
I use the following code to initialize the picker and obtain the value:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [self.pickerArray count];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
self.valueOne = (NSNumber *)[self.pickerArray objectAtIndex:row];
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.pickerArray objectAtIndex:row];
}
Looking at it now, I think the simplest solution is to just set self.valueOne
(name changed solely for this thread) to the desired value straight away. So in my viewDidLoad
method, I've included:
self.valueOne = @45;
This does the job, so I'll just leave it at that. Simple enough work-around. But please feel free to add to a different solution