Sto costruendo un'app in Swift che fa molto affidamento su Table Views. Utilizza sia le intestazioni che i piè di pagina, oltre alla cancellazione delle righe. Per qualche strana ragione quando eseguo l'eliminazione di una riga, l'intestazione e il piè di pagina seguono il movimento di scorrimento della riga da eliminare. Gli screenshot qui sotto spiegano cosa intendo.Perché le intestazioni e i piè di pagina seguono il movimento della riga quando lo si elimina?
Come si fa a evitare questo?
sto implementando la funzione di eliminazione come questa:
// Deleting
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Handling data source updating, cell row deletion, transition...
}
}
E l'intestazione e piè di pagina in questo modo:
// ## Header ##
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCellWithIdentifier("shoppingHeader") as! ShoppingTableViewHeaderCell
// Clear up 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 is 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 to 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 to show that footer moves too.
footerCell.backgroundColor = UIColor.blackColor() //clearColor()
return footerCell
}
come si creano le intestazioni e un piè di pagina? –
@VladimirKravchenko Sto aggiungendo il codice come da protocollo. Penso ... Ho aggiornato la domanda, per includere questo codice. –