Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must call a designated initializer of the superclass 'UITableViewCell'

   let bubbleView : UIView = {

    let view = UIView()
    view.backgroundColor = blueColor
    view.translatesAutoresizingMaskIntoConstraints = false
    view.layer.cornerRadius = 16
    view.layer.masksToBounds = true
    return view
}()


let messageImageView : UIImageView = {

    let imageView = UIImageView()
    imageView.translatesAutoresizingMaskIntoConstraints = false
    imageView.layer.cornerRadius = 16
    imageView.layer.masksToBounds = true
    imageView.contentMode = .scaleAspectFill
    return imageView

}()
init(frame: CGRect) {

    super.init(frame: frame)
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

// getting error in like "super.init(frame: frame)" as Must call a designated initializer of the superclass 'UITableViewCell'please help me in sorting this problem thanks in advance...

like image 305
Sri Vathsav Avatar asked Sep 07 '17 13:09

Sri Vathsav


2 Answers

I guess the code that you provided is from UITableViewCell type class. So in the initializer you should call designed initializer for this class. Not from UIView

The designated initializer for UITableViewCell class is

init(style: UITableViewCellStyle, reuseIdentifier: String?)

So in you class you should override this initializers:

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
}
like image 138
kamwysoc Avatar answered Sep 19 '22 14:09

kamwysoc


From the docs for init(style: UITableViewCellStyle, reuseIdentifier: String?):

This method is the designated initializer for the class.

The super initializer you're calling is for UIView, not UITableViewCell.

like image 39
Phillip Mills Avatar answered Sep 20 '22 14:09

Phillip Mills