본문 바로가기
모바일/IOS

TableVIew에서 이미지사용시 이미지변경이 느릴때 prepareForReuse()

by 죠부니 2018. 1. 17.
반응형

prepareForReuse()

https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse


설명이 잘되어있는 사이트

https://medium.com/ios-seminar/why-we-use-dequeuereusablecellwithidentifier-ce7fd97cde8e


class BestTableViewCell: UITableViewCell {
    
    // MARK: - Instance Vars
    @IBOutlet weak var mainStackView: UIStackView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var mainImageView: UIImageView!
    @IBOutlet weak var bodyLabel: UILabel!
    
    // MARK: - View Lifecycle
    override func awakeFromNib() {
        super.awakeFromNib()
        
        styleSetup()
    }
    
    override func prepareForReuse() {
        super.prepareForReuse()
        
        mainImageView.af_cancelImageRequest() // NOTE: - Using AlamofireImage
        mainImageView.image = nil
    }
}

// MARK: - Setup
extension BestTableViewCell {
    
    func styleSetup() {
        mainImageView.layer.borderWidth = 0.5
        mainImageView.layer.borderColor = UIColor.lightGray.cgColor
    }
    
}
override func prepareForReuse() {
mainImageView.af_cancelImageRequest()
mainImageView.image = nil
}


반응형