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

爷,独闯天下 提交于 2019-12-07 18:08:42

问题


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.


回答1:


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:.




回答2:


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.



来源:https://stackoverflow.com/questions/13075474/how-to-call-pickerview-didselectrow-incomponent-without-user-interaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!