1337code
1337code

Reputation: 169

UIPickerView select value when View is loaded

So I implemented a PickerView and everything works fine when I pick some value, but if I don't pick anything the

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

is not called. And I want if user doesn't pick a value, the first value is picked.

So I implemented:

-(void)viewDidAppear:(BOOL)animated
{
    [pickerView selectRow:0 inComponent:0 animated:YES];
}

but it doesn't work. Why isn't selectRow:inComponent: method called after this?

Upvotes: 0

Views: 339

Answers (2)

Oscar Apeland
Oscar Apeland

Reputation: 6662

Make a new function to be called when you start. If you want the code input to be read when you start the app, you need to put it under the viewDidLoad

- (void)viewDidLoad
{
[super viewDidLoad];
[updateWheel];
{
    [super viewDidLoad];
    }

 #Pragma Mark pickerWheel Delegate
- (void)updateWheel
{NSString *wheel1 = [wheel1 objectAtIndex:[picker selectedRowInComponent:0]];
aLabelUWantToHaveOutputIn.text = wheel1; 
} //Whatever code you want to happen

If this doesn't help, take a look at my project which uses some of the same mechanics. http://pastebin.com/WLGq3jvv

Upvotes: 2

Ramaraj T
Ramaraj T

Reputation: 5230

    [pickerView selectRow:0 inComponent:0 animated:YES];

It will not call the delegate function. It will simply scrolls the specified row to center.

Upvotes: 0

Related Questions