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 i开发者_StackOverflow中文版s 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,
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.
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.
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.
精彩评论