从视图控制器调用app delegate方法 [英] Call app delegate method from view controller
本文介绍了从视图控制器调用app delegate方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我是否可以从另一个ViewController调用app delegate方法。
I want to know if I can call an app delegate method from another ViewController.
当应用启动时,应用程序(应用程序: UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool
调用i方法。我可以从另一个视图控制器再次调用此方法吗?
When the app starts, the application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
i method is called. Can I call this method a second time from another view controller?
推荐答案
不确定为什么要这样做。您可能不应该,但为了回答这里的问题,它是:
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)
这篇关于从视图控制器调用app delegate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文