我有一个UITableView,可以在点击特定单元格时进行扩展。我的问题是,在第一次加载或扩展表时,附加单元正确加载内容,但连续关闭和扩展表的东西加载不正确。
我的代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let currentCellDescriptor = getCellDescriptorForIndexPath(indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: currentCellDescriptor["cellIdentifier"] as! String, for: indexPath) as! CustomCell
if currentCellDescriptor["cellIdentifier"] as! String == "idCellTextfield" {
cell.photo.image = globalVariable.images2[(indexPath as NSIndexPath).row]
cell.name.text = globalVariable.names2[(indexPath as NSIndexPath).row]
cell.price.text = globalVariable.prices2[(indexPath as NSIndexPath).row]
cell.unitPrice.text = globalVariable.unitPrice2[(indexPath as NSIndexPath).row]
cell.pPrice.text = globalVariable.previousPrice2[(indexPath as NSIndexPath).row]
//This is the portion of code that loads incorrectly
//This code identifies if an item is on special (true or false) and if it is adds a border to the left of the cell, specifies saving amount and changes the colour and style of some labels.
if globalVariable.specialBool2[(indexPath as NSIndexPath).row] == true {
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: globalVariable.previousPrice2[(indexPath as NSIndexPath).row])
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length))
cell.pPrice.attributedText = attributeString;
cell.price.textColor = UIColor(red: 214/255, green: 14/255, blue: 0/255, alpha: 1.0)
cell.layer.addBorderWatchlist(UIRectEdge.left, color: UIColor(red: 214/255, green: 14/255, blue: 0/255, alpha: 1.0), thickness: 6)
cell.savingAmount.text = globalVariable.savingAmount2[(indexPath as NSIndexPath).row]
} else if globalVariable.specialBool2[(indexPath as NSIndexPath).row] == false {
cell.pPrice.text = " "
cell.savingAmount.text = " "
cell.savingLbl.isHidden = true
cell.savingAmount.isHidden = true
}
}
cell.delegate = self
return cell
}
我需要在代码的相关部分更改什么才能确保每次扩展表时内容都能正确重新加载?