title: Getting/Setting UITextField value in a table cell
body: <p>For my current project i need to have a table in which contains textfield in each cell, the number of cells and textfield must be dynamic, it's depends on the number of data in a MutuableArray. I have the textfield in cells working, but i can't get/set the textfield value. I wonder if you guys can help me out or at least correct me what I did wrong? Thank's alot in advance. See code snippets below:</p>
  
  <pre><code>// Adds textfield into cell
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
      static NSString *CellIdentifier = @"Cell";
      UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
      if (cell == nil) {
          NSUInteger row = indexPath.row;
          X10ArchiefIndexDefs *curIndex = [indexDefinities objectAtIndex:row];
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  
          BOOL bShowSelection = ([curIndex.HasVasteWaarden isEqualToString:@"false"]);
  
          if (bShowSelection) {
              bShowSelection = !([curIndex.DataType isEqualToString:@"Datum"]);
          }
  
          if ([indexPath section] == 0) {
              if (bShowSelection) {
                  cell.accessoryType = UITableViewCellAccessoryNone;
              } else {
                  cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
              }
  
              UITextField *editField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
              editField.adjustsFontSizeToFitWidth = YES;
              editField.textColor = [UIColor blackColor];
              editField.placeholder = curIndex.Naam;
              editField.keyboardType = UIKeyboardTypeDefault;
              editField.returnKeyType = UIReturnKeyNext;
              editField.backgroundColor = [UIColor whiteColor];
              editField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
              editField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
              editField.textAlignment = UITextAlignmentLeft;
              editField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
              editField.tag = [curIndex.UID intValue];
  
              [editField setEnabled: YES];
              [cell addSubview:editField];
  
              [editField release];
          }
      }
  
      return cell;
  }
  </code></pre>
  
  <p>In some case i'm using popovercontroller to display list of data. User can select a value uit of the popup. This code is executed when there is a value selected:</p>
  
  <pre><code>- (void)selectedValue:(NSString *) value {
  
      //---update value of the text field ---
      //The first attempt it doesn't put the text to text field
  
      //static NSString *CellIdentifier = @"Cell";
      //UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      //
      //if (cell == nil) {
      //  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      //}
  
      // second attempt it crashes 
      X10ArchiefIndexDefs *curIndex = [indexDefinities objectAtIndex:curRow.row];
      int index = [curIndex.UID intValue];
      UITextField *textField = (UITextField *) [curCell viewWithTag: index];
      if (textField) {
              [textField setText:value];
      }
  
      [textField release];
  
      [self.popOverController dismissPopoverAnimated:YES];
  }
  </code></pre>
  
  <p>When cell is selected I'm making sure that the cell is saved for use later.</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  
      X10ArchiefIndexDefs *curIndex = [indexDefinities objectAtIndex:indexPath.row];
  
      if (!curIndex) {
          return;
      }
  
      curRow = indexPath; // saves the selected row
  
      if ([curIndex.VasteWaarden count] &gt; 0) {
          UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
          curCell = cell; // saves the selected cell
  
          CGRect frame = [cell.superview convertRect:cell.frame toView:self.view];
  
          self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];          
          detailViewController.delegate = self;
          self.popOverController = [[[UIPopoverController alloc] initWithContentViewController:detailViewController] autorelease];               
  
          X10ArchiefIndexDefs *curIndex = [indexDefinities objectAtIndex:indexPath.row];
          self.detailViewController.Values = curIndex.VasteWaarden;
  
          [self.popOverController presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
      }
  }
  </code></pre>
  
  <p>Again thank's alot in advance.</p>
  
  <p>Cheers,
  Inoel</p>