jeudi 25 juin 2015

UITableViewCell subclass IBOutlets returns nil

I've set up an UITableViewCell subclass from storyboard and connected the subviews as IBOutlets, as you can check here:

public class WaitingStatusTableViewCell: UITableViewCell {

@IBOutlet weak var leftBoxView: UIView!
@IBOutlet weak var leftTimeLabel: UILabel!
@IBOutlet weak var leftTitleLabel: UILabel!

Overrided the initialisers:

 override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)

required public init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

And on the initialConfigure function I try to configure some properties of my subviews

    func initialConfigure() {
    self.leftBoxView.backgroundColor = UIColor.clearColor()
    self.leftBoxView.layer.shadowColor = UIColor.darkGrayColor().CGColor
    self.leftBoxView.layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: 12.0).CGPath
    self.leftBoxView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
    self.leftBoxView.layer.shadowOpacity = 1.0
    self.leftBoxView.layer.shadowRadius = 2
    self.leftBoxView.layer.masksToBounds = true
    self.leftBoxView.clipsToBounds = false

It doesn't work at all, I receive the following error:

fatal error: unexpectedly found nil while unwrapping an Optional value

Any ideas?

Oh, by the way, it works on drawsRect function, but I really want to understand the "why"

See more ..

Aucun commentaire:

Enregistrer un commentaire