ios - Why do headers and footers follow movement of row when deleting it? -


i'm building app in swift relies heavily upon table views. uses both headers , footers, row deletion. strange reason when perform row deletion, header , footer follows sliding movement of row deleted. below screenshots explain mean.

enter image description here

how avoid this?

i'm implementing delete function this:

// deleting override func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {     if editingstyle == .delete {          // handling data source updating, cell row deletion, transition...      } } 

and header , footer this:

// ## header ## override func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? {     let headercell = tableview.dequeuereusablecellwithidentifier("shoppingheader") as! shoppingtableviewheadercell      // clear startup background     headercell.textlabel?.backgroundcolor = uicolor.clearcolor()      // add covering background color     headercell.backgroundcolor = uicolorfromhex(0x22b8a3, alpha: 1)      // set store image, or store title if image unavailable     let url = nsurl(string: datasource[sortedstores[section]]["meta_data"]["logo"].string!)     let data = nsdata(contentsofurl: url!)     if data != nil { // store image         let image = uiimage(data: data!)         headercell.imageview?.image = imageresize(image: image!, cellwidth: 90, cellheight: 30)     } else { // store name label         headercell.textlabel?.text = datasource[sortedstores[section]]["meta_data"]["namestore"].string         headercell.textlabel?.font = uifont(name: "helveticaneue-light", size: 16)         headercell.textlabel?.textcolor = uicolor.whitecolor()     }      // right hand side details: define strings     let address = datasource[sortedstores[section]]["meta_data"]["street"].string     let distancemeasure = datasource[sortedstores[section]]["meta_data"]["distance"].int!     let numberofoffers = datasource[sortedstores[section]]["offers"].count      // right hand side details: assign strings variables     headercell.rightlabel0.text = address     headercell.rightlabel1.text = "\(distancemeasure) m away"     if numberofoffers == 1 {         headercell.rightlabel2.text = "1 offer available"     } else {         headercell.rightlabel2.text = "\(numberofoffers) offers available"     }      // right hand side details: set text color     headercell.rightlabel0.textcolor = uicolor.whitecolor()     headercell.rightlabel1.textcolor = uicolor.whitecolor()     headercell.rightlabel2.textcolor = uicolor.whitecolor()      return headercell }   // ## footer ## override func tableview(tableview: uitableview, viewforfooterinsection section: int) -> uiview? {     let footercell = tableview.dequeuereusablecellwithidentifier("shoppingfooter") as! uitableviewcell      // set black color show footer moves too.     footercell.backgroundcolor = uicolor.blackcolor() //clearcolor()      return footercell } 

i think using reusable cells headers , footers problem. try use nibs instead. create separate .xib files header , footer cells. , cell with:

let headercell = nsbundle.mainbundle().loadnibnamed("yournibname", owner: self, options: nil).first as! shoppingtableviewheadercell 

or implement uitableviewheaderfooterview's subclass, create nib it, register nib with:

 tableview .registernib(uinib(nibname:"yournibname", bundle: nil), forheaderfooterviewreuseidentifier: "tableheader")  

and header's view with:

let header = tableview.dequeuereusableheaderfooterviewwithidentifier("tableheader") 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -