gpt4 book ai didi

ios - 从以编程方式创建的 UIPickerView 获取数据

转载 作者:行者123 更新时间:2023-11-28 22:13:03 24 4
gpt4 key购买 nike

我有一个手动编程的 UIPickerView,这样我就可以添加秒数。 UIPickerView 允许您选择小时、分钟和秒。我很难弄清楚如何从这个选择器中获取数据以便我可以存储它。有人能帮我吗?苹果预先制作的所有属性都可以轻松调用以获取值,但由于我使用的是自己的属性,所以我不确定如何处理它。谢谢!

我的 didSelectRow 方法

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSInteger hRow = [timerDurationPicker selectedRowInComponent:0];
NSInteger mRow = [timerDurationPicker selectedRowInComponent:1];
NSInteger sRow = [timerDurationPicker selectedRowInComponent:2];
}

最佳答案

如果你想在 UIPickerView 滚动结束后获取选中的行。然后你需要添加 UIPickerView. 的 valueChanged 事件

[myPickerView addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];

添加方法名是

-(void)valueChange:(UIPickerView *) picker
{
NSLog (@"%@", [picker selectRow:0 inComponent:0 animated:YES]); // set row and component value.
}

pickerView:didSelectRow:inComponent 是一个返回组件中选中行的委托(delegate)方法,这里需要设置你的行和组件。

编辑:

试试下面的代码

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

int hRow = [[arrayOfHour objectAtIndex:[timerDurationPicker selectedRowInComponent:0]] intValue];
int mRow = [[arrayOfMinute objectAtIndex:[timerDurationPicker selectedRowInComponent:1]] intValue];
int sRow = [[arrayOfSecond objectAtIndex:[timerDurationPicker selectedRowInComponent:2]] intValue];

NSLog (@"%d", hRow);
NSLog (@"%d", mRow);
NSLog (@"%d", sRow);
}

只是提出我的建议 - 使用 UIDatePicker (with time Mode) 而不是使用 UIPickerView,它是非常易于管理,您无需获取/管理小时、分钟和秒的数组。

关于ios - 从以编程方式创建的 UIPickerView 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22419518/

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