What i have so far is
@synthesize txtCountry,txtState;
int flgTextField;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[pickerView reloadAllComponents];
// Make a new view, or do what you want here
if(textField == txtCountry || textField == txtState){
flgTextField = textField.tag;
[UIView beginAnimations:nil context:NULL];
//[pvState setFrame:CGRectMake(0.0f, 199.0f, 320.0f, 216.0f)];
[UIView commitAnimations];
return NO;
}
else {
return YES;
}
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
if(flgTextField==1){
return [arryCountry count];
}
else {
return [arryState count];
}
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if(flgTextField==1){
return [arryCountry objectAtIndex:row];
}
else{
return [arryState objectAtIndex:row];
}
}
- (void)viewDidLoad {
arryCountry = [[NSMutableArray alloc] init];
arryState = [[NSMutableArray alloc] init];
[arryCountry addObject:@" 100 "];
[arryCountry addObject:@" 200 "];
[arryCountry addObject:@" 400 "];
[arryCountry addObject:@" 600 "];
[arryCountry addObject:@" 1000 "];
[arryState addObject:@" a "];
[arryState addObject:@" b "];
[arryState addObject:@" c "];
[arryState addObject:@" d "];
[arryState addObject:@" e "];
[super viewDidLoad];
}
in my .m
and
@interface Contact : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
IBOutlet UITextField *txtCountry;
IBOutlet UITextField *txtState;
NSMutableArray *arryCountry;
NSMutableArray *arryState;
UIPickerView *pickerView;
}
@property(nonatomic,retain) IBOutlet UITextField *txtCountry;
@property(nonatomic,retain) IBOutlet UITextField *txtState;
in my .h file
Now the text fields are not editable and I need some help or guidance, or any tutorial on how to connect UIPicker with multiple sources that can be change when text fields are editing
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…