iPhone:多个 UIPickerView

发布于 2024-11-04 09:02:51 字数 166 浏览 4 评论 0原文

我在 iPhone 应用程序中使用多个 UIPickerView 。我的问题是,如何处理多个 UIPickerView 处理事件?

另外,我想将选定的值放置在不同 UIPickerViewsUITextField 中。

I use a multiple UIPickerView in iPhone application. My question is, how can I handle multiple UIPickerView Handle Events?

Also, I want to place the selected value In UITextField of different UIPickerViews.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萧瑟寒风 2024-11-11 09:02:51

在每个委托中,您都有触发委托的 UIPickerView 的引用。例如:

-(void)PickerView 中的组件数量:(UIPickerView*)thePickerView

您有 thePickerView 变量指向响应此操作的控件,您现在需要做的就是区分您的UIPickerViews 如下:

 if (thePickerView == firstPickerView)

或者使用 Tag 属性

 if (thePickerView.tag == 1)

我会选择标签解决方案;比较 int 更快。

如何获取所选值:

至于 UIPickerView 的所选值,您可以使用委托来实现:

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

您将需要使用这里使用相同的技术;区分您的 UIPickerView 并获取该数据源的选定行,然后就完成了

 MyTextField.text = [theSelectedListArray objectAtIndex:row];

In each delegate you have reference of the UIPickerView which got triggered the delegate. for instance:

-(void)numberOfComponentInPickerView:(UIPickerView*)thePickerView

You have thePickerView variable which points to the control responded to this action, all you need to do now is to distinguish between your UIPickerViews as the following:

 if (thePickerView == firstPickerView)

Or Using The Tag property

 if (thePickerView.tag == 1)

I would go with the tag solution; comparing int is way faster.

How do I get the selected value:

As for the selected value of UIPickerView you can do that by using the delegate:

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

You will need to use the same technique here; distinguish between your UIPickerView and get the selected row for that data source and you are done

 MyTextField.text = [theSelectedListArray objectAtIndex:row];
清风不识月 2024-11-11 09:02:51
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    NSInteger counter;
    if(pickerView==p1)
    {
        counter=[name count];
    }
    else
    {
        counter=[name2 count];
    }
    return counter;

}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if(pickerView==p1)
        return [name objectAtIndex:row];//name is NsMutable Array
    else
        return [name2 objectAtIndex:row];//name2 is NsMutable Array

}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    NSInteger counter;
    if(pickerView==p1)
    {
        counter=[name count];
    }
    else
    {
        counter=[name2 count];
    }
    return counter;

}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if(pickerView==p1)
        return [name objectAtIndex:row];//name is NsMutable Array
    else
        return [name2 objectAtIndex:row];//name2 is NsMutable Array

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文