user2722667 user2722667 - 1 year ago 775
Swift Question

Swift iOS TableView cell items disappears when scrolling

When I scroll through my tableview I see that some badges in my list disappears.

My cell is set to have a custom class of



import UIKit

class CustomTableViewCell: UITableViewCell {

@IBOutlet weak var badgeIcon: AsyncImageView!
@IBOutlet weak var title: UILabel!

func configureCell(data: JSON) {

if let itemType = data["item_type"].int, itemTitle = data["item_type"].string {

title.text = itemTitle

if itemType == 1 {
badgeIcon.hidden = true
} else {
badgeIcon.hidden = false


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("myCustomCell") as! CustomTableViewCell

let data = items[indexPath.row]

//Dont show highlight
cell.selectionStyle = UITableViewCellSelectionStyle.None

return cell


When my tableView first loads everything is displayed right with badgeIcon being shown/hidden where it should be, but if I scroll up/down a few times the badgeIcon will always remain hidden

Answer Source

Within your UITableViewCell subclass, override prepareForReuse with:

badgeIcon.hidden = true

This way you can use a "clean slate" when configuring your cells upon reuse.