![](/img/trans.png)
[英]Must call a designated initializer of the superclass 'UICollectionView'
[英]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)
}
//像“super.init(frame:frame)”那樣得到錯誤,因為必須調用超類“UITableViewCell”的指定初始化程序,請幫我排序這個問題,感謝提前...
我猜你提供的代碼來自UITableViewCell
類型。 因此,在初始化程序中,您應該為此類調用設計的初始化程序。 不是來自UIView
UITableViewCell
類的指定初始化程序是
init(style: UITableViewCellStyle, reuseIdentifier: String?)
所以在你的課堂上你應該覆蓋這個初始化器:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
從init(style: UITableViewCellStyle, reuseIdentifier: String?)
的文檔init(style: UITableViewCellStyle, reuseIdentifier: String?)
:
此方法是類的指定初始值設定項。
您調用的super
初始化程序是UIView
,而不是UITableViewCell
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.