代码改变世界

Class 'ViewCell' has no initializers

2017-06-15 12:14  dengchaojie_learner  阅读(818)  评论(0编辑  收藏  举报

Class 'ViewCell' has no initializers

all variables must have an initialized value in Swift except Optional.

import UIKit

 

class InterestCollectionViewCell: UICollectionViewCell {

    

    @IBOutlet weak var tuPian: UIImageView!

    

    @IBOutlet weak var wenZi: UILabel!

    

    var interet: Interest! {// 如果不确定是否有值,用?

        didSet {

            updateUI()

        }

    }

    

    fileprivate func updateUI() {

        self.tuPian?.image! = interet.featuredImage

        self.wenZi?.text! = interet.title

    }

    

    override func layoutSubviews() {

        super.layoutSubviews()

        

        self.layer.cornerRadius = 5.0

        self.clipsToBounds = true

        

    }

 

}