ios - UITableView displays last item from array in every cell -


i'm using array of instances of same struct populate tableview , i'm stumped last item in array displaying in every cell.

class routesviewcontroller: uiviewcontroller, uitableviewdatasource {  @iboutlet weak var routestableview: uitableview!   func numberofsections(in tableview: uitableview) -> int {     return 1 }  func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {     return type1unownedroutesarray.count }  func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     let routecell = routestableview.dequeuereusablecell(withidentifier: "routecell") as! routetableviewcell        flight in type1unownedroutesarray {         routecell.originlabel.text = "origin:          \(flight.origin)"         routecell.destinationlabel.text = "destination: \(flight.destination)"         routecell.pricelabel.text = "price: $\(flight.popularity)"     }   return routecell } 

and struct itself:

struct flight {  var origin: string var destination: string var mileage: int var popularity: int var isowned: bool  } 

if add [indexpath.row] after for flight in type1unownedroutesarray type flight not conform protocol sequence

thanks in advance help.

the source of issue 1 in cellforrow method, cycling on flights objects in array, , of course last value keeping in cell, need replace this

    func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     let routecell = routestableview.dequeuereusablecell(withidentifier: "routecell") as! routetableviewcell      flight in type1unownedroutesarray {         routecell.originlabel.text = "origin:          \(flight.origin)"         routecell.destinationlabel.text = "destination: \(flight.destination)"         routecell.pricelabel.text = "price: $\(flight.popularity)"     }   return routecell } 

by this

   func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {    let routecell = routestableview.dequeuereusablecell(withidentifier: "routecell") as! routetableviewcell      let flight = type1unownedroutesarray[indexpath.row]     routecell.originlabel.text = "origin:          \(flight.origin)"     routecell.destinationlabel.text = "destination: \(flight.destination)"     routecell.pricelabel.text = "price: $\(flight.popularity)"  } 

hope helps


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -