ios - TableView rows re-ordering unexpectedly -
i having problem uitableview not preserving row order when row's come on screen.
after scrolling down/up order messed up. row index 1 in row 5's position , on. how keep row positions constant?
internal func tableview( tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath ) -> uitableviewcell { var cell:uitableviewcell? = tableview.dequeuereusablecellwithidentifier( "cell" ) as? uitableviewcell if cell == nil { cell = uitableviewcell(style: uitableviewcellstyle.subtitle, reuseidentifier: "cell" ) // set cell's label cell?.textlabel?.text = "cell: \(indexpath.row)" } // return cell return cell! }
what doing wrong?
you setting text when creating cell (when dequeuereusablecellwithidentifier
returns nil
). should set/change text each time create or reuse cell:
internal func tableview( tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath ) -> uitableviewcell { var cell:uitableviewcell? = tableview.dequeuereusablecellwithidentifier( "cell" ) as? uitableviewcell if cell == nil { cell = uitableviewcell(style: uitableviewcellstyle.subtitle, reuseidentifier: "cell" ) } // set cell's label cell?.textlabel?.text = "cell: \(indexpath.row)" // return cell return cell! }
Comments
Post a Comment