简体   繁体   English

必须调用超类'UITableViewCell'的指定初始值设定项

[英]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... //像“super.init(frame:frame)”那样得到错误,因为必须调用超类“UITableViewCell”的指定初始化程序,请帮我排序这个问题,感谢提前...

I guess the code that you provided is from UITableViewCell type class. 我猜你提供的代码来自UITableViewCell类型。 So in the initializer you should call designed initializer for this class. 因此,在初始化程序中,您应该为此类调用设计的初始化程序。 Not from UIView 不是来自UIView

The designated initializer for UITableViewCell class is UITableViewCell类的指定初始化程序是

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)
}

From the docs for init(style: UITableViewCellStyle, reuseIdentifier: String?) : init(style: UITableViewCellStyle, reuseIdentifier: String?)的文档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 . 您调用的super初始化程序是UIView ,而不是UITableViewCell

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 必须调用超类“UICollectionView”的指定初始值设定项 - Must call a designated initializer of the superclass 'UICollectionView' 必须调用超类'UITableViewHeaderFooterView'的指定初始值设定项 - Must call a designated initializer of the superclass 'UITableViewHeaderFooterView' Swift必须调用超类uiinputviewcontroller的指定初始值设定项 - Swift Must call a designated initializer of the superclass uiinputviewcontroller 必须调用超类“ UIViewController”的指定初始化程序 - Must call a designated initializer of the superclass 'UIViewController' 不能子类UIButton:必须调用超类'UIButton'的指定初始值设定项 - Cannot subclass UIButton: Must call a designated initializer of the superclass 'UIButton' 必须在Swift 1.2中调用超类'UIViewController'的指定初始化程序 - Must call a designated initializer of the superclass 'UIViewController' in Swift 1.2 Swift - 必须调用超类 SKSpriteNode 错误的指定初始值设定项 - Swift - Must call a designated initializer of the superclass SKSpriteNode error Swift:“必须调用超类的指定初始化程序”错误,即使代码正在这样做 - Swift: “Must call a designated initializer of the superclass” error even though code is doing so 将超类 init 方法链接到指定的初始化程序 - Link superclass init method to designated initializer 找不到超类'-init'的指定初始化方法的方法重写 - Method override for the designated initializer of the superclass '-init' not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM