How to write init methods of a UIViewController in Swift

前端 未结 8 1557
长发绾君心
长发绾君心 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:11

    Correct flow is, call the designated initializer which in this case is the init with nibName,

    init(tap: UITapGestureRecognizer)
    {
        // Initialise the variables
        tap = UITapGestureRecognizer(target: self, action: Selector(("handleTap:")))
    
        // Call the designated init of ViewController
        super.init(nibName: nil, bundle: nil)
    
        // Call your viewcontroller custom methods here
        setupViewControllers()
    }
    

提交回复
热议问题