UIPickerView, how to fire a on-change event to initialise
When my PickerView is dis开发者_开发技巧played, I need to fire a selection event so that a text field is updated (as on load up it is blank), below is the method that responds to change events:
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// update things
}
the best I can come up with is (in viewDidLoad of ViewController):
[self pickerView: pickerView didSelectRow: 0 inComponent 0]
this causes an error
"instance method - pickerView: didSelectRow: inComponent:' not found return type defaults to 'id')" but it works?!
(I've named my UIPickerView object 'pickerView' by the way!)
If I understand this correctly, you want to select a row as soon as the UIPickerView appears on the screen. pickerView:didSelectRow:inComponent
is a delegate method (a callback method) that the picker view calls when the user selects a row. It is not to be called by you.
To select a row, use the picker view's selectRow:inComponent:animated:
method.
[self.pickerView selectRow:0 inComponent:0 animated:YES];
精彩评论