我正在使用双(双组件)选择器 View 。当我运行它时,它会显示双选择器 View ,但两个组件的行中的信息相同。
这是代码希望你能帮助我。
我想在第一个组件中显示 array1,在第二个组件中显示 array2。
- (void)viewDidLoad {
NSArray *FirstArray1 = [[NSArray alloc] initWithObjects:
@"White",@"Whole Wheat",@"Rye",@"Sourdough",@"Seven Grain", nil];
self.Array1 = FirstArray1;
NSArray *FirstArray2 = [[NSArray alloc] initWithObjects:
@"Turkey",@"eanut Butter",@"Tuna Salad",@"Chicken Salad",@"Roast Beef",
@"Vegemite",nil];
self.Array2 = FirstArray2;
[super viewDidLoad];
}
-(NSInteger)numberOfComponentsInPickerViewUIPickerView *)pickerView
{
return 2;
}
-(NSInteger)pickerViewUIPickerView *)pickerView
numberOfRowsInComponentNSInteger)component
{
return[self.Array1 count];
return[self.Array2 count];
}
-(NSString *)pickerViewUIPickerView *)pickerView
titleForRowNSInteger)row
forComponentNSInteger)component
{
return [self.Array1 objectAtIndex:row];
return [self.Array2 objectAtIndex:row];
}
Best Answer-推荐答案 strong>
-(NSInteger)pickerViewUIPickerView *)pickerView
numberOfRowsInComponentNSInteger)component
{
if (component == 0) {
return[self.Array1 count];
} else if (component == 1) {
return[self.Array2 count];
}
return 0;
}
关于ios - 双(双组件)选择器 View 的问题,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/9199891/
|