ios - Swift - UITableViewCell with custom class and prototype repeating after 4th cell -
in application, have uitableview
dynamically creates new cells user clicks on "add" button. cells have several fields intended take user input. however, after creating fourth cell, cell contains duplicates of input added in first cell. example, each cell had textfield
firstcell.textfield.text = 0 <--- manually assigned secondcell.textfield.text = 1 <--- .. thirdcell.textfield.text = 2 <---- .. fourthcell.textfield.text = 0 <--- automatically assigned fifthcell.textfield.text = 1 <--- automatically assigned
after digging, believe due cells being dequeued using reuse identifier , cells being reused. how can create multiple cells same prototype, not automatically hold manually assigned values previous cell?
update:
func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("mycustomcell", forindexpath: indexpath) as! custonuitableviewcellclass cellb.delegate = self return cell }
i tried assigning each cell's ui element in function according indexpath.row, doesn't seem working. it'd working fine until start scrolling after adding 4 rows, cell in first row return indexpath.row = 4 , ui elements in first row assigned value inputted on fourth row.
as said, cells being reused , that's why experiencing weird behavior. need hold on assigned values each cell , clean/set each cell every time reused in cellforrowatindexpath
.
since have textfield use delegate respond it's text being changed , save value in array, every time cell reused value , set it.
Comments
Post a Comment