ios - Swift tableViewCell keep duplicating on scroll -


i've read every thread about

if(cell == nil) 

but throws error incomparable. i've been trying days tableviewcells stop duplicating when exists. help!! title in section headers duplicate , overlay each other. i'm assuming images duplicating well. when test on iphone scrolling laggy.

viewcontroller.swift  import uikit import swiftyjson import alamofire import avfoundation   class viewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource  {  @iboutlet weak var navigationbar: uinavigationitem! @iboutlet weak var tableview: uitableview!  var list = [] var audioplayer:avaudioplayer!  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func getlistbro() -> nsarray {     return list }  override func viewdidload() {     super.viewdidload()     // additional setup after loading view, typically nib.     tableview.datasource = self;     tableview.delegate = self;     self.tableview.rowheight = uitableviewautomaticdimension        let streamurl = nsurl(string: "http://localhost:8000/beat-stream-all/")!      let stuff = getbeatstream(url:streamurl)     self.tableview.rowheight = uitableviewautomaticdimension;     self.tableview.estimatedrowheight = 50.0; //     stuff.downloadjsonfromurl {         (let jsondictionary) in             if let jsonlist = jsondictionary["results"] as? nsarray {                 self.list = jsonlist             }               let priority = dispatch_queue_priority_default             dispatch_async(dispatch_get_global_queue(priority, 0)) {                 // task                 dispatch_async(dispatch_get_main_queue()) {                     // update ui                     self.tableview.reloaddata()                 }             }     }  }//end view did load   func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      let cell = tableview.dequeuereusablecellwithidentifier("streamcell") as? streamtableviewcell          if let beat_cover = list[indexpath.section] as? nsdictionary {             if let beat_cover_image = beat_cover["beat_cover"] as? string {                 cell?.beatcover.image =  uiimage(data: nsdata(contentsofurl: nsurl(string:beat_cover_image)!)!)             }         }           if let descriptionsection = list[indexpath.section] as? nsdictionary {             if let description = descriptionsection["description"] as! nsstring? {                     cell?.beatdescription.text = description string                  cell?.beatdescription.linebreakmode = nslinebreakmode.bywordwrapping         }      }        if let audio = list[indexpath.section] as? nsdictionary {         if let audio_url = audio["audio"] as? string {                 cell?.url = audio_url                 cell?.buildplayer()         }     }      return cell! }  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return 1 }  func numberofsectionsintableview(tableview: uitableview) -> int {     return list.count }  func tableview(tableview: uitableview, willdisplayheaderview view: uiview, forsection section: int) {  //        username     let beatauthorlabel = uilabel(frame: cgrectmake(55, 5, 200, 40))      //user pic     let profilepictureimageview = uiimageview(frame: cgrectmake(5, 5, 40, 40));     profilepictureimageview.layer.borderwidth = 0     profilepictureimageview.layer.maskstobounds = false     profilepictureimageview.layer.bordercolor = uicolor.blackcolor().cgcolor     profilepictureimageview.layer.cornerradius = profilepictureimageview.frame.height/2     profilepictureimageview.clipstobounds = true     profilepictureimageview.layer.maskstobounds = true       if let userpicsection = list[section] as? nsdictionary {         if let artist = userpicsection["artist"] as? nsdictionary {             if let profilepic = artist["profile_pic"] as? string {                 let image = uiimage(data: nsdata(contentsofurl: nsurl(string:profilepic)!)!)                 profilepictureimageview.image = image;             }         }     }       if let namesection = list[section] as? nsdictionary {         if let name = namesection["artist"] as? nsdictionary {             if let adminname = name["admin_name"] as? nsstring {                 beatauthorlabel.text = adminname string             }         }     }      let datelabel = uilabel(frame: cgrectmake(225, 5, 200, 40))     if let created = list[section] as? nsdictionary {         if let date = created["created_at"] as? string {             datelabel.text = date string             datelabel.font = uifont(name: datelabel.font.fontname, size: 8)          }     }      let header: uitableviewheaderfooterview = view as! uitableviewheaderfooterview     header.addsubview(beatauthorlabel)     header.addsubview(datelabel)     header.contentview.addsubview(profilepictureimageview)     header.contentview.backgroundcolor = uicolor(red: 179/255, green: 194/255, blue: 191/255, alpha:1)     header.textlabel!.textcolor = uicolor.whitecolor()     header.alpha = 1  }  func tableview(tableview: uitableview, heightforheaderinsection section: int) -> cgfloat {     return 50 }  func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {     let indexpath = tableview.indexpathforselectedrow     let currentcell = tableview.cellforrowatindexpath(indexpath!)! as! streamtableviewcell     currentcell.player.play() }  func tableview(tableview: uitableview, didenddisplayingcell cell: uitableviewcell, forrowatindexpath indexpath: nsindexpath) {     let leavingcell = cell as! streamtableviewcell     leavingcell.player.pause() }     } 


Comments