gpt4 book ai didi

ios - 如何将2个UIpickerView添加到一个UIview中?

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

我有点懵。我有一个主要的 UIView 并且我在主要的中粘贴了 2 个 UIViews。在每个“ child ”-UIView 中,我都有一个 UIPickerView。我的问题是第一个 UIPickerView 具有以下功能,但不知道如何为第二个执行此操作。有人可以帮我吗?

-(NSInteger)numberOfComponentsInPickerView:(UIViewController *)pickerView{
return 1;
}


-(NSInteger)pickerView:(UIViewController *)pickerView numberOfRowsInComponent:(NSInteger)component{
if(component==option)
return[options count];
return 0;

}


-(NSString *)pickerView:(UIViewController *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(component==option)
return[options objectAtIndex:row];
return 0;
}


-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
_optionLabel.text=[options objectAtIndex:[myPickerView selectedRowInComponent:0]];
}

那么,有什么方法可以将这些功能复制到我的第二个 pickerView 吗?

最佳答案

您需要像这样设置选择器 View 标签

#Updated

myPickerView.tag = 1; //It's for first PickerView
directionTranslationPickerView.tag = 2; //It's for second PickerView

请在创建 pickerview 的地方实现这两行。

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
if (pickerView.tag==1) {
return 1; //It's for first PickerView
}else{
return 1; // It's for second pickerview
}

}


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if (pickerView.tag==1) {
if(component==option)
return[options count]; //It's for first PickerView
return 0;

}else{

// It's for second pickerview
return 0;

}

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (pickerView.view.tag==1) {
if(component==option)
return[options objectAtIndex:row]; //It's for first PickerView
return 0;
}else{
// It's for second pickerview
}

}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView.view.tag==1) {
_optionLabel.text=[options objectAtIndex:[myPickerView selectedRowInComponent:0]]; //It's for first PickerView

}else{
// It's for second pickerview
}
}

试试这个可能对你有帮助。注意:您需要为您的 UIPickerView 设置标签 must

关于ios - 如何将2个UIpickerView添加到一个UIview中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24007134/

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