Reputation: 346
I've been looking for quite a while after an answer for this, but can't seem to fint the solution... Whenever I open my picker I need to pull the screen a little bit in order for the first row to get "picked" otherwise it will return a blank string. Is there a way to by default autoselect the first row so that you wont need to do this motion?
Thanks in advance
Upvotes: 0
Views: 115
Reputation: 7333
You just declare NSString in your .h file
NSString *strVal;
then in your viewDidLoad method assign your default value to the string
strVal=your default value;
and your delegate method :
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:
(NSInteger)component
{
strVal=assign element;
}
Upvotes: 0
Reputation: 14068
Use
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
to set any default value that you want.
Upvotes: 2
Reputation: 9975
You could use:
[pickerView selectRow:0 inComponent:0 animated:NO]
In your viewDidLoad method.
Upvotes: 1