xcode 必须调用超类“UITableViewCell”的指定初始值设定项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46097450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Must call a designated initializer of the superclass 'UITableViewCell'
提问by Sri Vathsav
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'的指定初始值设定项,请帮我解决这个问题,提前谢谢...
回答by kamwysoc
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
我猜您提供的代码来自UITableViewCell
类型类。因此,在初始化程序中,您应该为此类调用设计的初始化程序。不是来自UIView
The designated initializer for UITableViewCell
class is
UITableViewCell
类的指定初始值设定项是
init(style: UITableViewCellStyle, reuseIdentifier: String?)
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)
}
回答by Phillip Mills
From the docs for 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
。