我已經採用2個數組來傳遞相應選取器視圖中的數據。我已通過UITextField
的Picker Views。我有2個文本字段在特定的文本字段選擇相關的選擇器視圖應該出現。我嘗試了一些方法仍然沒有結果。如何在同一個類中的兩個選取器視圖之間切換
下面的代碼:
//First Picker View
self.pickerFillStatus = [[UIPickerView alloc]init];
self.pickerFillStatus.showsSelectionIndicator = YES;
self.pickerFillStatus.delegate = self;
self.pickerFillStatus.dataSource =self;
self.fillArray = [NSArray arrayWithObjects:@"Single",@"Married Filling Jointly",@"Married Filling Separately",@"Head of House Hold",nil];
self.txtFillingStatus.inputView = self.pickerFillStatus;
self.txtFillingStatus.tag = 1;
// Second Picker View
self.pickerState = [[UIPickerView alloc]init];
self.pickerState.showsSelectionIndicator = YES;
self.pickerState.delegate = self;
self.pickerState.dataSource =self;
self.stateArray = [NSArray arrayWithObjects:@"SC",@"VT",@"OR",@"PA",@"RI",nil];
self.txtState.inputView = self.pickerState;
self.txtState.tag = 2;
// All the Datasource and Delegates
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
if (self.txtFillingStatus.tag == 1) {
return self.fillArray.count;
} else if (self.txtState.tag == 2) {
return self.stateArray.count;
}
return 0;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component
{
if (self.txtFillingStatus.tag == 1) {
[_txtFillingStatus setText:[self.fillArray objectAtIndex:row]];
}else if (self.txtState.tag == 2) {
[_txtState setText:[self.stateArray objectAtIndex:row]];
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:
(NSInteger)row forComponent:(NSInteger)component
{
if (self.txtFillingStatus.tag == 1) {
return [self.fillArray objectAtIndex:row];
}else if (self.txtState.tag == 2) {
return [self.stateArray objectAtIndex:row];
}
return nil;
}
顯示您textFieldDidBeginEditing:方法 – Smile
我不力添加方法@ismail – iDeveloper
- (空)textFieldDidBeginEditing:(*的UITextField)文本框添加此方法。並在此方法中,您可以使用工作@ismail – Smile