我有两个字段调用UIPickerView(国家和省份)。我正在使用inputView来显示选择器视图。两者都使用一个选择器视图,但如何根据字段填充?
这里我提供了示例代码
此代码在选择器视图事件后执行!有人建议我把这个代码放在正确的地方。
-(void)textFieldDidBeginEditing:(UITextField*)textField;
{
// Check if the field is Country
if (textField.tag == 3) {
pickerData = [[NSMutableArray alloc] init];
[pickerData addObject:@"Australia"];
[pickerData addObject:@"Canada"];
[pickerData addObject:@"India"];
[pickerData addObject:@"China"];
[pickerData addObject:@"United States"];
[pickerData addObject:@"United Kingdom"];
[pickerData addObject:@"New Zealand"];
txtCountry.inputView = picker;
picker.hidden = NO;
}
// Check if the field is Province
else if (textField.tag == 4) {
if ([[txtCountry text] isEqualToString: @"Canada"]) {
pickerData = [[NSMutableArray alloc] init];
[pickerData addObject:@"Quebec"];
[pickerData addObject:@"Ontario"];
[pickerData addObject:@"British Columbia"];
[pickerData addObject:@"Prince Evard Island"];
[pickerData addObject:@"Alberta"];
[pickerData addObject:@"Sascatchwan"];
txtProvince.inputView = picker;
picker.hidden = NO;
}
else {
txtProvince.inputView = nil;
picker.hidden = YES;
}
}
else {
picker.hidden = YES;
}
}
答案 0 :(得分:1)
您是否已将其数据源设置为pickerData?
您可以调用方法[yourPickerData reloadAllComponents];