UITabelViewCell中的子视图UITextField人工输入字符后,上下拖动UITableView到他重用,输入的数据丢失

解决思路,创建字典接受数据,利用tag值得唯一性。进行保存。

1、首先创建字典,然后对字典进行初始化

  NSMutableDictionary*diccc;

  diccc= [NSMutableDictionarydictionary];

2、然后在重用cell的方法里面遵守UItexfeild协议,设置tag,保存字典。

  #pragma mark----重用cell

  -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

staticNSString*ce =@"cell";

TableViewCell*cell = [tabcellForRowAtIndexPath:indexPath];

if(cell ==nil) {

cell = [[TableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:ce];

}

cell.lab.text=array[indexPath.row];

cell.text1.delegate = self;

cell.text1.tag = indexPath.row;

cell.text2.delegate = self;

cell.text2.tag = indexPath.row + 100;

[cell.text1 addTarget:self action:@selector(textFiled:) forControlEvents:UIControlEventAllEditingEvents];

[cell.text2addTarget:selfaction:@selector(textFiled:)forControlEvents:UIControlEventAllEditingEvents];

if([chooseArraycontainsObject:cell.lab.text]) {

cell.selectBt.image= [UIImageimageNamed:@"evaluation_selected"];

}else{

cell.selectBt.image= [UIImageimageNamed:@"evaluation_unselected"];

}

cell.text1.text = diccc[[NSString stringWithFormat:@"%d", cell.text1.tag] ];

cell.text2.text=diccc[[NSStringstringWithFormat:@"%d",indexPath.row+100]];

returncell;

}

//保存数据

  - (void)textFiled:(UITextField*)field {

[dicccsetObject:field.textforKey:[NSStringstringWithFormat:@"%d", field.tag]];;

}

你可能感兴趣的:(UITabelViewCell中的子视图UITextField人工输入字符后,上下拖动UITableView到他重用,输入的数据丢失)