gpt4 book ai didi

ios - 如何以编程方式选择 UIPickerView 行并执行关联的方法

转载 作者:行者123 更新时间:2023-11-29 02:43:39 24 4
gpt4 key购买 nike

我有一个应用程序,它使用两个组件 UIPickerView 并根据所选的各个行执行代码。当我手动选择行时一切正常;但是,当我尝试以编程方式执行此操作时,行标题会适当更新,但相关方法不会执行。

我设置了一个每秒触发一次的 NSTimer,我想执行与

关联的代码
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

每次这个计时器触发。

我试过:

[_eventPicker reloadAllComponents];
[_eventPicker selectRow:currentEventComponent inComponent:0 animated:NO];
//my UIPickerView property is named _eventPicker, and I have an int currentEventComponent
//that is set when the user selects the row

将其放入我的 autoRefresh 方法中,该方法每秒由计时器激活一次;然而,没有任何反应。但是,当我离开当前行并用拇指手动返回时,一切都会正确执行。

所以我的问题是,您如何通过我的自动刷新计时器每秒以编程方式执行 pickerView didSelectRow?我做错了什么?

最佳答案

您当然可以自己调用委托(delegate)方法。

[self pickerView: myPickerView 
didSelectRow:[myPickerView selectedRowInComponent:component]
inComponent:component];

如果您知道它是什么 component,或者如果只有一个,则只知道 0——您就明白了。如果你不这样做,就说你想检查每个组件:

for (NSInteger component = 0; component < myPickerView.numberOfComponents; ++component)
[self pickerView: myPickerView
didSelectRow:[myPickerView selectedRowInComponent:component]
inComponent:component];

您当然可以将 didSelectRow 调用路由到您自己的方法,与 didSelectRow 相比,您可以更轻松地调用自己的方法。 “伪造”回调似乎有点卑鄙。另见 this question .

关于ios - 如何以编程方式选择 UIPickerView 行并执行关联的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25415680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com