Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top