2017-06-05 12 views
0

現在、私のUIにはサーバからの応答に基づいてUITextFieldの配列を作成しました。私の応答には単一APIの3種類の応答が含まれています。私は日付を選択するとテキストフィールドの配列で選択したUITexFiled値を変更する方法

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]; 
    } 

:私は値がその特定のここTextFiled

私のサンプルコードに応じて変更する必要がありますUITextFiledを選択すると、値がこれに基づいて文字列、日付、配列、のようなタイプが含まれています値は最後のオブジェクトにUITextfieldに入力されましたが、インデックスは2番目に選択されましたが、UITextfieldの最後の要素で値が変更されます

答えて

関連する問題