Can I programmatically scroll to a desired row in UIPickerView? Can I programmatically scroll to a desired row in UIPickerView? ios ios

Can I programmatically scroll to a desired row in UIPickerView?


As always, this is thoroughly documented. The Apple documentation for UIPickerView should tell you that the method you probably want is – selectRow:inComponent:animated:.


If you want to trigger delegate's method pickerView:didSelectRow:inComponent, you should call it manually:

Obj-C

[self.myPickerView selectRow:0 inComponent:0 animated:NO];[self pickerView:self.myPickerView didSelectRow:4 inComponent:0];

Swift

self.myPickerView.selectRow(0, inComponent: 0, animated: false)self.pickerView(self.myPickerView, didSelectRow: 0, inComponent: 0)


Yes, it's very easy [picker selectRow:row inComponent:component animated:NO];