UITableView reusable custom cells displaying incorrect content in subheadings
I have a subclass of UITableViewController in which I populate the UITableView with data like this:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("kundeCell") as! KundeCell
cell.selectionStyle = .None
let kunde = self.kundenAuszutragen[indexPath.row]
cell.delegate = self
cell.kunde = kunde
cell.allowsSwypeRight = (self.zahlungenImQuartalVonKunde[kunde] == nil) // Abkassieren
cell.allowsSwypeLeft = self.state == .Austragen // Austragen
cell.abkassierButton.titleAbkassierLabel.showsTextFilled = self.zahlungenImQuartalVonKunde[kunde] != nil
return cell
}
This works great, it looks like:
The top text is the UILabel, the bottom text is from the UIButton (default in both cases). The € sign on the right is a custom UIButton with a look at a custom UILabel that displays a € effect with a hit effect, here is the corresponding code for the custom UIButton that is called when the button is not set:
private func handleInit()
{
// titleAbkassierLabel is the custom UILabel with the stroke
self.titleAbkassierLabel = AbkassierLabel(frame: CGRect(x: 0, y: 0, width: self.bounds.size.width, height: self.bounds.size.height))
self.titleAbkassierLabel.font = UIFont.systemFontOfSize(self.titleAbkassierLabelFontSize)
self.titleAbkassierLabel.text = self.titleText
self.titleAbkassierLabel.textColor = UIColor.clearColor()
self.titleAbkassierLabel.setNeedsDisplay()
self.addSubview(self.titleAbkassierLabel)
self.backgroundColor = UIColor.clearColor()
}
Now, when I set the e sign of the cell to be filled, it looks like this:
The following code is called in the UIButton subclass:
self.titleAbkassierLabel.showsTextFilled = true
// which then again comes to: (in the titleAbkassierLabel - property)
var showsTextFilled: Bool = true {
didSet
{
self.setNeedsDisplay()
}
}
So good, this cell is "highlighted" filled. But if I scroll down, the other cells are also highlighted (of course, because the first cell is re-used, why it shows the correct text (in the labels on the left), but do not sign on the right cells that should not stand even in contrast to the other? (Cf. its with a different cell, it seems that it is thicker)
So, it looks fatter, but if I look in the ViewDebugger I see that there is only one custom button and one custom € sign:
If you need more information, just comment. Thanks a lot and I hope you understand the problem despite the German property names / etc!
EDIT: My Cell delegate:
protocol AustragenAbkassierenDelegate
{
// Kunde bearbeiten
func setKundeAusgetragen(kunde: Kunde, animated: Bool) -> Bool
func setKundeAbkassiert(kunde: Kunde, createZahlung: Bool, endAction: (() -> Void)?) -> UIAlertController?
func getNextKundeAfterKunde(kunde: Kunde) -> Kunde?
func showKundeDetailVCWithKunde(kunde: Kunde)
func showAlertController(alert: UIAlertController!, completionHandler: (() -> Void)?)
}
But I don't think it has anything to do with this issue. It's just to notify the delegate (here TableViewController) when something has changed.
source to share