ios : display the array value in uitextfield?
在文本字段中显示键值。
这就是我获取数据的方式:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if (txtviolation.editing == YES) [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]]; pickerV = [[UIPickerView alloc]init]; [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]]; |
这是显示数据的方式:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{ if (flag==1) { return ViolationA.count; } else if (flag==2) { return VTypeA.count; } return 0; } – (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component return 0; -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component txtviolation.text =[NSString stringWithFormat:@”%@”, [ViolationA objectAtIndex:row]]; } |
我无法绑定:
点击文本框然后打开 uipicker 视图但不显示标题名称只显示 ‘{‘ 符号。
然后滚动它以设置数组键和值的值,但我只设置值。
1
2 3 4 5 6 7 8 9 10 11 |
uitextfield setvalue:
{ “violation_name” =”Street Light”; } and uipickerview display: then to select any value to set in text field. |
uipickerview 执行选择文本字段不使用任何按钮
- 你的编码很好,我认为你的数组包含另一个索引,所以试试 txtviolation.text =[[ViolationA objectAtIndex:row]objectatindex:0];,实际上我们不知道你的 ViolationA 包含什么
- @Nilesh:您的代码根本不干净,不必要重复相同的代码…请通过此链接 stackoverflow.com/a/11612702/1570609
- @property(strong, nonatomic) NSMutableArray *ViolationA; @property(strong, nonatomic) NSMutableArray *VTypeA;
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{ return 1; } -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component – (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component }
-(void)textFieldDidBeginEditing:(UITextField *)textField if (txtviolation.editing == YES) |
来源:https://www.codenong.com/31825707/