-1

I am trying to select the first row as default.. Here i tried

-(void)pickerViewLoaded{

   [pickerView setShowSelectionIndicator:YES];
   pickerView.delegate = self;
   [pickerView reloadAllComponents];
   [pickerView selectRow:1 inComponent:0 animated:YES]
}

It works fine when i call this method on viewDidLoad() which call didSelectRow method but it is selecting the second row of that component not first one. when i call with [pickerView selectRow:0 inComponent:0 animated:YES] then it never call didSelectRow method.

another problem is when i call pickerViewLoaded method on selection of segmented control it does not call the didSelectRow method. i still could not figure when it may call with viewDidLoad then why not with segmentedControl.

Thanks all,

Kshitiz Ghimire
  • 1,716
  • 3
  • 18
  • 37
Praveen
  • 31
  • 1
  • 2
  • 5

3 Answers3

2

seems to be a old thread, anyway I thought of sharing my experience.

I had the same issue and moved the

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

to

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

I call the selectRow:inComponent:animated only after returning the titleForRow called for last-row using a notification.

palaniraja
  • 10,432
  • 5
  • 43
  • 76
1

Now that the question has been raised from the dead...

I think selectRow uses an index that starts at 0 - not 1. So 0 is the first row, and 1 is the second row.

Kolya Miller
  • 185
  • 4
  • 12
1

I just ran into the same problem and figured it out: The delegate doesn't get called, if the selected row doesn't change. Also, row 0 is selected by default, so re-selecting row 0 in viewDidLoad doesn't trigger the delegate. In my case I was able to call the delegate method directly, maybe that's the solution in your case, too.

Sebastian
  • 2,109
  • 1
  • 20
  • 15