[英]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.