Call app delegate method from view controller

后端 未结 4 731
自闭症患者
自闭症患者 2021-01-01 17:57

I want to know if I can call an app delegate method from another ViewController.

When the app starts, the application(application: UIApplication, didFinishLaun

4条回答
  •  醉酒成梦
    2021-01-01 18:23

    Not sure why you want to do this. You probably shouldn't, but for the purpose of answering the question here it is:

    // get a reference to the app delegate
    let appDelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
    
    // call didFinishLaunchWithOptions ... why?
    appDelegate?.application(UIApplication.shared, didFinishLaunchingWithOptions: nil)
    

提交回复
热议问题