Tom
Tom

Reputation: 346

Autoselect picker row

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

Answers (3)

V-Xtreme
V-Xtreme

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

Hermann Klecker
Hermann Klecker

Reputation: 14068

Use

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated 

to set any default value that you want.

Upvotes: 2

Asciiom
Asciiom

Reputation: 9975

You could use:

[pickerView selectRow:0 inComponent:0 animated:NO]

In your viewDidLoad method.

Upvotes: 1

Related Questions