【发布时间】:2017-06-05 07:26:35
【问题描述】:
目前,我在 UI 中基于来自服务器的响应创建了 UITextField 数组,我的响应在单个 API 中包含三种类型的响应,即我得到 5 个键和值。值包含字符串、日期、数组等类型,基于此,当我选择 UITextFiled 时,值必须根据特定的 TextFiled 更改
这是我的示例代码:
for (int i=0;i<itemAttributeArray.count;i++){
UIColor *floatingLabelColor = [UIColor brownColor];
textField1 = [[JVFloatLabeledTextField alloc] initWithFrame:CGRectMake(16, y, width, height)];
textField1.delegate = self;
//Set tag 101
textField1.tag = 101;
NSLog(@"textField1.tag - %ld",(long)textField1.tag);
textField1.text = [[itemAttributeArray valueForKey:@"value"]objectAtIndex:i];
[self SetTextFieldBorder:textField1];
textField1.placeholder = [keyArr objectAtIndex:i];
textField1.font = [UIFont systemFontOfSize:kJVFieldFontSize];
// textField1.clearsOnBeginEditing = YES;
textField1.clearButtonMode = UITextFieldViewModeWhileEditing;
textField1.floatingLabelFont = [UIFont boldSystemFontOfSize:kJVFieldFloatingLabelFontSize];
textField1.floatingLabelTextColor = floatingLabelColor;
// textField1.translatesAutoresizingMaskIntoConstraints = NO;
[textField1 resignFirstResponder];
[_scroll addSubview:textField1];
[textFields addObject:textField1];
[textField1 release];
y += height + margin;
if ([[[itemAttributeArray valueForKey:@"type"] objectAtIndex:i] isEqualToString:@"string"]){
NSLog(@"type - %@",[[itemAttributeArray valueForKey:@"type"] objectAtIndex:i]);
}else if ([[[itemAttributeArray valueForKey:@"type"]
objectAtIndex:i] isEqualToString:@"date"]){
NSLog(@"type - %@",[[itemAttributeArray valueForKey:@"type"] objectAtIndex:i]);
textField1.tag = 102;
[textField1 addTarget:self action:@selector(textFieldDidChange_dateChek)
forControlEvents:UIControlEventEditingDidBegin];
}else if ([[[itemAttributeArray valueForKey:@"type"] objectAtIndex:i] isEqualToString:@"double"]){
NSLog(@"type - %@",[[itemAttributeArray valueForKey:@"type"] objectAtIndex:i]);
}
-(void)textFieldDidChange_dateChek{
NSLog(@"iam called on first edit");
_picker_uiView.hidden = false;
[_datePickerView addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
}
- (void)datePickerValueChanged:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
textField1.text = [dateFormatter
stringFromDate:_datePickerView.date];
}
当我选择在 UITextfield 的最后一个对象中输入日期值但我选择的索引是第二个但 UITextfield 的最后一个元素上的值发生变化时
【问题讨论】:
标签: ios objective-c delegates uitextfield