How to write init methods of a UIViewController in Swift

前端 未结 8 1565
长发绾君心
长发绾君心 2020-12-07 17:14

I am unable to add init method to the following UIViewController class. I need to write some code in the init method. Do i have to write init(coder) method? Even when I add

8条回答
  •  日久生厌
    2020-12-07 18:00

    I think you have to add

    required init(coder aDecoder: NSCoder) {
        print("init coder")
        super.init(coder: aDecoder)
    }
    

    or

    convenience init() {
        self.init()
    }
    

    You have to write init too. Don't remove it

    var tap: UITapGestureRecognizer?
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?)   {
        super.init(nibName: nil, bundle: nil)
    }
    

    Hope it helps

提交回复
热议问题