ios - UITextFields inside UITableViewCells - text disappears when cells go out of view -


i have uitableview bunch of uitableviewcells. these uitableviewcells have multiple uitextfields inside them.

now every time scroll , down, , uitableviewcells go out of view, , come in, whatever text had entered inside uitextfield disappears. best way make work?

static nsstring *cellidentifier = @"cell";  complaintscustomcell *cell=(complaintscustomcell*)[tableview dequeuereusablecellwithidentifier:cellidentifier];  if(cell==nil){     nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"complaintscustomcell" owner:self options:nil];      for(id currentobject in toplevelobjects){          if([currentobject iskindofclass:[uitableviewcell class]]){             cell = (complaintscustomcell *) currentobject;             break;         }     } }  cell.durationfld.text=[dict valueforkey:@"duration"]; [cell.durationfld settag:indexpath.row + 5000]; 

your code seems have 2 issues:

  1. you're setting cells' text fields exact same value of [dict valueforkey:@"duration"]
  2. it appears [dict valueforkey:@"duration"] has no value, explains why text fields empty code called again.

i think should create simple class has property replan nsarray , initialize whatever initial values of text fields are. whenever text field changes, replace array object @ same index of indexpath.row new text. in original cellforrowatindexpath method, should assign text field's text this:

cell.durationfld.text = [valuesarray objectatindex:indexpath.row]; 

if deal lot of text fields, i'd recommend taking @ free sensible tableview framework. luck!


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -