2014-10-03 42 views
-1

我有一个TableView(名为myTableView),其中包含ViewController(不是TableViewController,名为:ViewController)中的原型单元格(命名为TableCell)从TableCell修改NSMutableArray

每个单元格都有4个不同的显示来自不同NSMutableArrays(在ViewController.h中声明并命名为:Legajos,Nombres,Cbus,Sueldos,Contribuciones)的数据的文本字段,例如,第0行的单元格将显示索引处的对象0来自Legajos,Nombres等...所有这些工作,我甚至可以添加和删除没有问题的行。

现在我的问题。我有textfields(声明TableCell.h)显示来自NSMutableArrays(在ViewController.h中声明)的文本,但我只能使它成为一个“单程旅行”,也就是说,文本字段只显示来自NSMutableArrays的文本但我也需要它们来修改NSMutableArray,以便保存该数组然后加载它。

的NSMutableArrays声明:(ViewController.h)

@property (strong, nonatomic) NSMutableArray *Legajos; 
@property (strong, nonatomic) NSMutableArray *Nombres; 
@property (strong, nonatomic) NSMutableArray *Cbus; 
@property (strong, nonatomic) NSMutableArray *Sueldos; 
@property (strong, nonatomic) NSMutableArray *Contribuciones; 

这里是细胞如何得到他们的文字:(ViewController.m)

cell.legajo.text = [Legajos objectAtIndex:indexPath.row]; 
cell.nombre.text = [Nombres objectAtIndex:indexPath.row]; 
cell.cbu.text = [Cbus objectAtIndex:indexPath.row]; 
cell.sueldo.text = [Sueldos objectAtIndex:indexPath.row]; 
cell.contribucion.text = [Contribuciones objectAtIndex:indexPath.row]; 

这是细胞的IBOutlets: (TableCells.h)

@property (strong, nonatomic) IBOutlet UILabel *legajo; 
@property (strong, nonatomic) IBOutlet UITextField *nombre; 
@property (strong, nonatomic) IBOutlet UITextField *cbu; 
@property (strong, nonatomic) IBOutlet UITextField *sueldo; 
@property (strong, nonatomic) IBOutlet UITextField *contribucion; 

对不起,如果它很难理解。感谢您给予的任何帮助。

+0

当单元格被修改时,您需要修改数组。你会在UITextFieldDelegate方法中做到这一点。 – 2014-10-03 02:02:24

+0

@HotLicks事情是我不知道如何修改位于ViewController _from TableCell_上的NSMutableArray。我知道如何修改一个数组。 – 2014-10-03 02:15:19

+0

文本字段委托应该知道如何修改它。代表创建时简单地说明传递可寻址性的问题。 (并且请注意,ViewController中的TableView与TableViewController之间没有实质区别。) – 2014-10-03 02:24:20

回答

0

Easieast方式可能会将(void) textFieldDidEndEditing:(UITextField *)textField方法添加到您的UITextField委托。您可以在创建时为每个UITextField分配一个标签,以便知道要编辑哪个数组,或者我相信NSIndexPath *indexPath = [self.tableView indexPathForCell:(CustomCell*)[[textField superview] superview]];可能会做到这一点。

(void) textFieldDidEndEditing:(UITextField *)textField { 
     NSIndexPath *indexPath = [self.tableView indexPathForCell:(CustomCell*)[[textField superview] superview]]; 

     switch(indexPath.section) 
    { 
     case '0': 
      // edit object in first array at index indexPath.row 
      [firstArray replaceObjectAtIndex:indexPath.row withObject:textField.text]; 
      break; 
     case '1': 
      // edit object in second array at index indexPath.row 
      [secondArray replaceObjectAtIndex:indexPath.row withObject:textField.text]; 
      break; 
     case '2': 
      // edit object in third array at index indexPath.row 
      [thirdArray replaceObjectAtIndex:indexPath.row withObject:textField.text]; 
      break; 
     case '3': 
      // edit object in fourth array at index indexPath.row 
      [fourthArray replaceObjectAtIndex:indexPath.row withObject:textField.text]; 
      break; 
     case '0': 
      // edit object in fifth array at index indexPath.row 
      [fifthArray replaceObjectAtIndex:indexPath.row withObject:textField.text]; 
      break; 
     default : 
      } 

    } 

这是我输入的一个简单例子。