简体   繁体   中英

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. 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,

> override init(frame: CGRect) {
          super.init(frame: frame)
          rightAnswer = true
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM