[英]Must call a designated initializer error
import UIKit
class RightAnswerButtonClass: UIButton {
var rightAnswer: Bool
init() {
super.init()
rightAnswer = false
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
I am trying to create a custom class button with the variable "rightanswer" stored as a bool.我正在尝试创建一个自定义类按钮,其中变量“rightanswer”存储为 bool。 However, when I try to build, I recieve the error "Must call a designated initializer"
但是,当我尝试构建时,收到错误“必须调用指定的初始化程序”
It's compile time error where super class designated initialisation not implement.超类指定的初始化未实现是编译时错误。 As subclass of UIButton must implement(override) init(frame:CGRect)("Designated Initialiser for UIButton") like as below,
由于 UIButton 的子类必须实现(覆盖)init(frame:CGRect)("Designated Initialiser for UIButton") 如下所示,
> override init(frame: CGRect) {
super.init(frame: frame)
rightAnswer = true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.