Sergey Katranuk
Sergey Katranuk

Reputation: 1182

How to call pickerView: didSelectRow: inComponent: without user interaction?

I have a 2 components, dependent pickerView. I have a preview UIImageView that changes each time the user uses the pickerView (and triggers the didSelectRow:inComponent:). This works just as I expected.

However, I want the pickerView to trigger didSelectRow: when the app launches, so that there is a Preview the moment the user sees the UIImageView. In viewDidLoad, when I try this:

[self pickerView:picker didSelectRow:row inComponent:component]; // row and component have 0 values. 

next thing that happens - the pickerView shows up blank! Remove this line, and it works perfectly again. I tried this as well:

[picker selectRow: row inComponent:component animated:NO];

thinking that it will trigger didSelectRow: however it doesn't trigger it and my UIImageView remain blank.

Any advice on how to call the didSelectRow: method without the users help?

Update: by the way, the picker is inside another UIView (not the main one). In case it matters.

Upvotes: 4

Views: 6960

Answers (2)

iDev
iDev

Reputation: 23278

Based on your comments, this what you are looking for then. Does UIPickerView's selectRow:inComponent:animated: call pickerView:didSelectRow:inComponent:?

You have to manually call the didSelectRow method.

Upvotes: 3

Martin R
Martin R

Reputation: 539685

didSelectRow:... will only be called if a row has been selected by user interaction. If you select a row programmatically with selectRow:... then you have to add you own logic to update other components like the image view.

The principle is valid for many other delegate functions, such as e.g. tableView:didSelectRowAtIndexPath:.

Upvotes: 13

Related Questions