objective c - UITextField in UITableViewCell - reuse issue -


i have uitableview has custom uitableviewcell has uitextfield inside it.

each uitextfield displays text viewmodel , using reactive-cocoa bind textfields viewmodel.

when uitableview loads first time, works fine. when reload uitableview next 'page' - first uitextfield on reloaded (page two) tableview has exact same memory address first uitextfield in first 'page' - cell not same other ui elements correct - textfields same instance.

so, declared uitextfields in vc so:

@property (weak, nonatomic)  uitextfield *textfieldone; //one first 'page' @property (weak, nonatomic)  uitextfield *textfieldtwo; //after reload on second 'page'  

then setup in method invoked cellforrowatindexpath

 -(void)configuretextfieldcell:(bbtextfieldlabeltableviewcell *)cell atindexpath:(nsindexpath *)indexpath     {         cell.textfield.delegate = self;          if (self.selectedsegmentindex == segmentedcontrolstep1){             if (indexpath.section == 0){                              cell.label.text = @"name";                             self.textfieldone = cell.textfield;                     }                 /* code setting other cells / textfields ommited -                 same syntax above checks indexpath */                 }          if (self.selectedsegmentindex == segmentedcontrolstep2){                  cell.label.text = @"username";                 self.textfieldtwo = cell.textfield;              [self bindusernameandpasswordtoviewmodel]; /* binding textfield nil when vc loads first time,                                                             first chance bind on second page */         }     } 

inside bbtextfieldlabeltableviewcell uitextfield declared so:

@property (strong, nonatomic) iboutlet uitextfield *textfield; 

i tried doing inside cell's implementation file:

-(void)prepareforreuse {     self.textfield = [[uitextfield alloc] init]; } 

as thought issue possibly cell-reuse issue of sort. code made no difference.

so textfieldone , textfieldtwo both have exact same memory address , cannot figure out why.

would appreciate on - can't figure out have gone wrong.

inside cellforrowatindexpath create cell so:

bbtextfieldlabeltableviewcell *textfieldcell = [tableview dequeuereusablecellwithidentifier:textfieldcellidentifier]; 

in prepareforreuse creating new text-field neither removing old 1 nor adding new one.

i suggest using prepareforreuse reset current text field rather creating new one

reading question bit more carefully: fact textfield 1 , 2 both have same value, indicates prepare reuse not being called between 2 calls configuretextfieldcell. without more code, difficult understand why


Comments