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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -