UIPickerView:无法识别的选择器发送到实例

发布于 2024-12-20 12:40:31 字数 2255 浏览 1 评论 0原文

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

'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)];

想法?

I'm building a form for inputting data into a web database. Everything is going great, but I have to have multiple pickers with multiple sets of data. I'm trying to set up a class that I can instantiate and set as the data source and delegate to the pickers that I pull up, and had it to a point, but went with another method. Now I can't get it to load the data, giving me this error:

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

So here is my code for the picker class:

-(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;
}

And here is the actual picker itself.

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)];

Thoughts?

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

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

发布评论

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

评论(1

陌生 2024-12-27 12:40:31

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

I fixed this by running local variables and loading them all using the same class. I pulled these variables in using XML and made them on load of the picker.

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