具有变化值的 UIpicker 数组

发布于 2024-11-26 09:24:30 字数 716 浏览 1 评论 0原文

我正在制作一个应用程序,它使用选择器让用户选择年龄和其他一些输入。例如:我有一个按钮年龄,当用户单击它时,选择器会显示年龄。我设法为所有输入添加单独的选择器,但是我在为每个选择器设置不同的数组时遇到问题。

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
    if (pickerview == picker) {
        return [pickerViewArray objectAtIndex:row];
    }
    else if (pickerview == stagepicker)
        return [stagepickerarray objectAtInde:row];
    }
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
    if (thePickerView == picker){ return [pickerViewArray count]; }
    else if (thePickerView == stagepicker){ [stagepickerarray count]; }
}

上面的方法对我不起作用!我这样做对吗?

I'm making an app that uses the picker to let the user pick age and few other inputs. for eg: i have a button age, when the user clicks it, the picker shows the age. i managed to add individual picker for all the inputs, how ever i'm having problems setting different arrays for each picker.

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
    if (pickerview == picker) {
        return [pickerViewArray objectAtIndex:row];
    }
    else if (pickerview == stagepicker)
        return [stagepickerarray objectAtInde:row];
    }
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
    if (thePickerView == picker){ return [pickerViewArray count]; }
    else if (thePickerView == stagepicker){ [stagepickerarray count]; }
}

the above method isn't working for me !. Am I doing this right ?

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

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

发布评论

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

评论(2

携余温的黄昏 2024-12-03 09:24:30
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
    if (pickerview == picker) {

听起来不是应该将 pickerview 写成 thePickerView 吗?

return [stagepickerarray objectAtInde:row];

是不是听起来 objectAtInde 应该是 objectAtIndex

else if (thePickerView == stagepicker){ [stagepickerarray count]; }

听起来是不是好像某处缺少 return

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
    if (pickerview == picker) {

Doesn't it sound like pickerview should be written thePickerView instead?

return [stagepickerarray objectAtInde:row];

Doesn't it sound like objectAtInde should be objectAtIndex?

else if (thePickerView == stagepicker){ [stagepickerarray count]; }

Doesn't it sound like a return is missing somewhere?

2024-12-03 09:24:30

为什么不将一个 UIPickerView 与多个组件一起使用?大致如下:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

NSInteger numberOfRows;

if (component == 0) {
     numberOfRows = [anArray count];
}
else if(component == 1) { 
    numberOfRows = [anotherArray count];
}
else { 
    numberOfRows = [aThirdArray count];
}

return numberOfRows;

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

NSString *stringIndex = [NSString stringWithFormat:@"TEST"];
if(component == 0) {

   return stringIndex = [anArray objectAtIndex:row];
}

else if(component == 1) {
    return stringIndex = [anotherArray objectAtIndex:row];
}

else {
   return stringIndex = [aThirdArray objectAtIndex:row];
}

return stringIndex;

}

Why not use one UIPickerView with multiple components? Something along the lines of:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

NSInteger numberOfRows;

if (component == 0) {
     numberOfRows = [anArray count];
}
else if(component == 1) { 
    numberOfRows = [anotherArray count];
}
else { 
    numberOfRows = [aThirdArray count];
}

return numberOfRows;

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

NSString *stringIndex = [NSString stringWithFormat:@"TEST"];
if(component == 0) {

   return stringIndex = [anArray objectAtIndex:row];
}

else if(component == 1) {
    return stringIndex = [anotherArray objectAtIndex:row];
}

else {
   return stringIndex = [aThirdArray objectAtIndex:row];
}

return stringIndex;

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