ios - how to avoid reusable custom cell from overwriting data when scrolling? -
this code using , works fine until scroll in table view, cells overwrite each others , repostedfromlabel hidden.
func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("feedstableviewcell", forindexpath: indexpath) as? feedstableviewcell if (arrayofpostsfeed[indexpath.row].postedbyuser!.nickname!) != arrayofpostsfeed[indexpath.row].ownedbyuser!.nickname! { cell!.repostedfromlabel.text! = "reposted \(self.arrayofpostsfeed[indexpath.row].postedbyuser!.nickname!)" } else { cell!.repostedfromlabel.hidden = true } }
how should prevent reusable cells override each others?
you can implement prepareforreuse function in feedstableviewcell reset hidden property of repostedfromlabel. this:
override func prepareforreuse() { self.repostedfromlabel.hidden = false }
at moment not resetting value, mixed when reusing cells.
Comments
Post a Comment