如何调用pickerView:didSelectRow:inComponent:没有用户交互? [英] How to call pickerView: didSelectRow: inComponent: without user interaction?

查看:73
本文介绍了如何调用pickerView:didSelectRow:inComponent:没有用户交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个组件,依赖 pickerView.我有一个预览 UIImageView 每次用户使用 pickerView 时都会改变(并触发 didSelectRow:inComponent:).这和我预期的一样工作.

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.

但是,我希望 pickerView 在应用启动时触发 didSelectRow:,以便在用户看到 UIImageView 时有一个预览代码>.在 viewDidLoad 中,当我尝试此操作时:

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. 

接下来发生的事情 - pickerView 显示为空白!删除此行,它再次完美运行.我也试过这个:

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];

认为它会触发 didSelectRow: 但是它不会触发它并且我的 UIImageView 保持空白.

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

关于如何在没有用户帮助的情况下调用 didSelectRow: 方法的任何建议?

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

更新:顺便说一下,选择器在另一个UIView(不是主要的)里面.万一有关系.

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

推荐答案

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

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.

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

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

这篇关于如何调用pickerView:didSelectRow:inComponent:没有用户交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆