我有一个 UIPickerView,我希望它有 2 列填充我的数组中的项目,但我不知道如何,有我的数组:
-(void)fillingStandartWeightArray{
if (!standartWeightArray){
for (int i=25; i<150 ;i++){
NSString *weightString;
weightString = [NSString stringWithFormat:@"%d kg", i];
[standartWeightArray addObject:weightString];
NSLog(@"%@", weightString);
}
}
}
-(void)fillingStandartHeightArray{
if (!standartHeightArray){
for (int i=85; i<250; i++){
NSString *heightString;
heightString = [NSString stringWithFormat:@"%d cm", i];
[standartHeightArray addObject:heightString];
NSLog(@"%@", heightString);
}
}
}
更具体地说,我不知道如何“告诉” UIPickerView 用一个数组填充其中一个轮子,而另一个用另一个数组填充轮子。我试过这个:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if (component == 0){
return [standartWeightArray count];
} else {
return [standartHeightArray count];
}
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == 0)
return [standartWeightArray objectAtIndex:row];
else if (component == 1)
return [standartHeightArray objectAtIndex:row];
}
我确实在 viewDidLoad 部分调用了函数:
- (void)viewDidLoad
{
[super viewDidLoad];
[self fillingStandartWeightArray];
[self fillingStandartHeightArray];
NSLog(@"%@", standartWeightArray);
}
但这行不通。