从视图控制器调用应用程序委托方法 [英] Call app delegate method from view controller

查看:29
本文介绍了从视图控制器调用应用程序委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以从另一个 ViewController 调用应用程序委托方法.

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

当应用程序启动时,application(application: 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)

这篇关于从视图控制器调用应用程序委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆