ios - UITextFields inside UITableViewCells - text disappears when cells go out of view -
i have uitableview
bunch of uitableviewcell
s. these uitableviewcell
s have multiple uitextfield
s inside them.
now every time scroll , down, , uitableviewcell
s 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:
- you're setting cells' text fields exact same value of
[dict valueforkey:@"duration"]
- 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
Post a Comment