3

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.

4

2 回答 2

12

didSelectRow:...只有当用户交互选择了一行时才会调用。如果您以编程方式选择一行,selectRow:...那么您必须添加自己的逻辑来更新其他组件,例如图像视图。

该原则适用于许多其他委托功能,例如tableView:didSelectRowAtIndexPath:.

于 2012-10-25T19:32:43.780 回答
3

根据您的评论,这就是您正在寻找的内容。 UIPickerView 的 selectRow:inComponent:animated: 是否调用 pickerView:didSelectRow:inComponent:?

您必须手动调用该didSelectRow方法。

于 2012-10-25T19:25:51.920 回答