title: UITableView update data on row selection
body: <p>I have a <code>UITableView</code> that get its data from an array and the array contains the filenames of a directory.</p>
  
  <p>I am trying to make user edit filename on row selection.</p>
  
  <p>My code is:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      [self editChattWithName:[self.listArray objectAtIndex:indexPath.row] atIndex:indexPath];
      [self.tabView deselectRowAtIndexPath:indexPath animated:YES];
  }
  
  - (void)editChattWithName:(NSString*)name atIndex:(NSIndexPath *)indexPath {
  
      UIAlertView* editAlert = [[UIAlertView alloc]
          initWithTitle:nil
          message:@"Edit FileName"
          delegate:self
          cancelButtonTitle:@"Cancel"
          otherButtonTitles:@"Update", nil];
      [editAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
  
      UITextField* nameField = [editAlert textFieldAtIndex:0];
      [nameField setPlaceholder:@"New FileName"];
      [nameField setText:name]; 
      [editAlert show];
      [editAlert release];
  
      NSString *newFileName = nameField.text;
      [editAlert showWithCompletion:^(UIAlertView *alertView, NSInteger buttonIndex) {
              if (buttonIndex == 0) {   }
              else if (buttonIndex == 1) { 
                  NSError *error;
                  // Edit filename inside directory
                  [fm moveItemAtPath:[NSString stringWithFormat:@"%@%@",directory,name] toPath:[NSString stringWithFormat:@"%@%@",directory,newFileName] error:&amp;error];
                  // Update value inside array
                  [self.listArray replaceObjectAtIndex:indexPath.row withObject:newChatName];
                  // reload table data to show new filename
                  [self.tabView reloadData];
                  NSLog(@"Old Filename: %@%@",directory,name);
                  NSLog(@"New Filename: %@%@",directory,newFileName);
                  NSLog(@"Error: %@",error);
                  }
              }];
  }
  </code></pre>
  
  <p>The issue is that <code>name</code> and <code>newFileName</code> are having the same value <code>name</code> and that is resulting an error with NSFileManager saying that the file already exists.</p>
  
  <p>I have tried removing <code>[nameField setText:name]</code> but the problem was still there.</p>
  
  <p>I am out of luck and not able to find the issue, your help is much appreciated.</p>