2011-12-08 116 views
0

我正在構建一個用於將數據輸入到Web數據庫的表單。一切都很順利,但我必須有多個採集器和多組數據。我試圖建立一個類,我可以實例化並將其設置爲數據源,並委託給我所選擇的拾取器,並將其放在一個點上,但使用另一種方法。現在,我不能得到它加載數據,給我這個錯誤:UIPickerView:發送到實例的無法識別的選擇器

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

想法?

回答

0

我通過運行局部變量並使用相同的類加載它們來解決此問題。我使用XML來拉取這些變量,並使它們在選取器的負載下進行。

相關問題