【发布时间】:2014-07-20 10:40:39
【问题描述】:
当我点击textField 时,打开UIPickerView 然后选择它在UITextField 上显示的PickerView 数据。
但现在我有 3 个 text_Filed(city,typeofcars,branches) 但我不知道 Single UIPickerView 上的三个 TextFiled。所以请给我任何想法。
单个文本-归档一个UIPickerview代码是:-
Businessname=[[UITextField alloc]init];
Businessname.frame=CGRectMake(0, 0, 221, 33);
Businessname.placeholder=@"Business Name";
[Businessname setFont:[UIFont fontWithName:@"Times New Roman" size:13]];
Businessname.backgroundColor=[UIColor whiteColor];
[Businessname setBorderStyle:UITextBorderStyleBezel];
Businessname.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Businessname.layer.borderColor=[[UIColor yellowColor]CGColor];
Businessname.layer.borderWidth= 2.0f;
Businessname.textColor=[UIColor blackColor];
[scrol addSubview:Businessname];
yourpicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 400, 100, 150)];
[yourpicker setDataSource: self];
[yourpicker setDelegate: self];
yourpicker.showsSelectionIndicator = YES;
Businessname.inputView = yourpicker;
[yourpicker setShowsSelectionIndicator:YES];
mypickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 300, 100, 56)];
mypickerToolbar.barStyle = UIBarStyleBlackOpaque;
[mypickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked)];
[barItems addObject:doneBtn];
[mypickerToolbar setItems:barItems animated:YES];
Businessname.inputAccessoryView = mypickerToolbar;
-(void)pickerDoneClicked
{
NSLog(@"Done Clicked");
[Businessname resignFirstResponder];
mypickerToolbar.hidden=YES;
yourpicker.hidden=YES;
}
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [pickarray count];
}
上面的代码是当我点击文本文件然后打开UIPIckerView然后选择数据时输出的。但是现在我有 3 个 TextFields 和 3 个 NSArrays 请如何根据 UITextField 将数据数据传递给 UIPickerView。
所以请给我关于我的问题的任何想法
感谢进阶
【问题讨论】:
-
也许如果你简化你的代码示例,去掉与这个问题无关的代码,我们就能更快地回答你
-
为每个
UITextField添加标签怎么样?然后你之前检查一下,根据字段标签加载数据。
标签: ios objective-c uitextfield nsarray uipickerview