[英]Dynamic UIPickerView with multiple TextField
I am using UIPickerView
with UITextField
. 我正在将
UIPickerView
与UITextField
。 It is working when I use only one UITextField
. 当我只使用一个
UITextField
时,它正在工作。 What I want is to use multiple TextField
for one dynamic pickerview
. 我想要的是对一个动态
pickerview
使用多个TextField
。
- (void)viewDidLoad
{
[super viewDidLoad];
picker = [[UIPickerView alloc] init];
picker.dataSource = self;
picker.delegate = self;
self.transitTF.inputView = picker;
self.theData = @[@"one",@"two",@"three",@"four"];
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return self.theData.count;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return self.theData[row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
self.transitTF.text = self.theData[row];
[self.transitTF resignFirstResponder];
}
This is what I use with one textField
only. 这是我仅使用一个
textField
。
Any help will be appreciated. 任何帮助将不胜感激。 Thanks.
谢谢。
Add tag property for each UITextField
. 为每个
UITextField
添加标签属性 。 In this case self.pickerView.inputView.tag
you may use to find which textfield is using in current moment and you may fill picker with correct values 在这种情况下,您可以使用
self.pickerView.inputView.tag
查找当前时刻正在使用的文本字段,并且可以使用正确的值填充选择器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.