title: How to create dynamic textfield , accessble and editable for each textfield in iOS
body: <p>Can anyone help me ? I want to create dynamic <code>text field</code> in side a loop.I have been able to create and made it editable too. My requirements are in below.
  i.I want to access each <code>text fields</code> value and make a sum of those will store in a <code>Label</code>.
  ii. Let's say there are 5 dynamic created text fields having value (10,20,30,40,50).
  so label displays sum of 5 value.  ie. 10+20+30+40+50 = 150
  if i make changes in either <code>textfield</code> values, it should recalculate and changes the total sum in <code>label</code>.
  my logic goes as below.</p>
  
  <p>-(void)create
  {</p>
  
  <pre><code>    myarr = [NSMutableArray arrayWithObjects:@"1000",@"2000",@"3000",@"4000",@"5000", nil];
  
  int x = 20, y = 50;
  int width = 280, height = 40;
  for (int item=0; item&lt;[myarr count]; item++)
  {
      edit_txt = [[UITextField alloc]initWithFrame:CGRectMake(x, y, width, height)];
      edit_txt.text = [NSString stringWithFormat:@"%@",[myarr objectAtIndex:item]];
      [edit_txt setTag:item+1];
      edit_txt.placeholder  = @"Click here to type";
      edit_txt.borderStyle = UITextBorderStyleRoundedRect;
      edit_txt.font = [UIFont systemFontOfSize:15];
      edit_txt.textAlignment = NSTextAlignmentLeft;
      edit_txt.returnKeyType = UIReturnKeyDefault;
      edit_txt.delegate = (id)self;
      [self.view addSubview:edit_txt];
      y += height;
  }
  
  tot_txt = [[UITextField alloc]initWithFrame:CGRectMake(edit_txt.frame.origin.x, edit_txt.frame.origin.y + height + 10, width , height)];
  tot_txt.placeholder  = @"Total Value";
  tot_txt.borderStyle = UITextBorderStyleRoundedRect;
  tot_txt.font = [UIFont systemFontOfSize:15];
  tot_txt.textAlignment = NSTextAlignmentLeft;
  tot_txt.returnKeyType = UIReturnKeyDefault;
  tot_txt.delegate = (id)self;
  [self.view addSubview:tot_txt];
  
  
  save_btn = [UIButton buttonWithType:UIButtonTypeCustom];
  [save_btn setFrame:CGRectMake(tot_txt.frame.origin.x, tot_txt.frame.origin.y + height + 10, width , height)];
  [save_btn setTitle:@"Save" forState:UIControlStateNormal];
  [save_btn addTarget:self action:@selector(save_click:) forControlEvents:UIControlEventTouchUpInside];
  [save_btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  [self.view addSubview:save_btn];
  CALayer *btnlayer = [save_btn layer];
  [btnlayer setBorderColor:[UIColor redColor].CGColor];
  [btnlayer setBorderWidth:0.3];
  [btnlayer setCornerRadius:20.0];
  </code></pre>
  
  <p>}</p>
  
  <pre><code>-(void)textFieldDidEndEditing:(UITextField *)textField
  </code></pre>
  
  <p>{
      int count = 0;</p>
  
  <pre><code>for (int item = 0; item &lt; [myarr count]; item++)
  {
      UITextField *textField = ([[self.view viewWithTag:item + 1] isKindOfClass:[UITextField class]])?(UITextField *)[self.view viewWithTag:item + 1]:nil;
      count += [textField.text intValue];
  }
  tot_txt.text = [NSString stringWithFormat:@"%d", count];
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks in advance.
  Ajeet Kumar.</p>