0

我正在构建一个用于将数据输入 Web 数据库的表单。一切都很顺利,但我必须有多个选择器和多组数据。我正在尝试设置一个可以实例化并设置为数据源的类,并委托给我拉起的选择器,并达到一定程度,但使用了另一种方法。现在我无法让它加载数据,给我这个错误:

'NSInvalidArgumentException', reason: '-[__NSArrayI numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x6c9c970'

所以这是我的选择器类代码:

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return myArray.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return [myArray objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    rowInt=row;

}

-(IBAction)setMyArray:(NSMutableArray *)incomingArray{
    myArray = incomingArray;
}

这是实际的选择器本身。

PickerViewLoader *source = [[PickerViewLoader alloc]init];
    myarray =[[NSMutableArray alloc] initWithObjects:@"a", @"b", @"c", @"d", @"e", nil];
    [source setMyArray:myarray];

    pickerAction=[[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    [pickerAction setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    CGRect pickerFrame = CGRectMake(0, 40, 0, 0);

    UIPickerView *carrierPicker =[[UIPickerView alloc]initWithFrame:pickerFrame];
    carrierPicker.showsSelectionIndicator=YES;
    carrierPicker.dataSource=source;
    carrierPicker.delegate=source;

    [pickerAction addSubview:carrierPicker];

    UISegmentedControl *closeButton=[[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObject:@"OK"] ];
    closeButton.momentary = YES;
    closeButton.frame=CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle =UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(closePicker) forControlEvents:UIControlEventValueChanged];
    [pickerAction addSubview:closeButton];

    [pickerAction showInView:self.view];
    [pickerAction setBounds:CGRectMake(0, 0, 320, 464)];

想法?

4

1 回答 1

0

我通过运行局部变量并使用同一个类加载它们来解决这个问题。我使用 XML 提取这些变量,并在加载选择器时制作它们。

于 2012-05-29T12:33:47.363 回答