来自appdelegate的viewcontroller中的访问方法 [英] Access method in viewcontroller from appdelegate

查看:111
本文介绍了来自appdelegate的viewcontroller中的访问方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为applicationDidBecomeActive使用appdelegate,我希望此函数使用放置在viewcontroller中的方法。我该怎么做?
我发现的唯一的东西就是从任何地方访问appdelegate。

I want to use appdelegate for applicationDidBecomeActive and I want this function to use method which is placed in viewcontroller. How I am gonna do that? The only thing that I find is to access from anywhere the appdelegate.

推荐答案

你需要给你的 applicationDelegate 类对您要调用该方法的 viewController 的引用。你可以通过创建一个指向你的 viewController 的实例变量或 applicationDelegate 的一个属性来实现这个功能。如果你在你的 appDelegate 的init方法或你的 applicationDidLoad:方法中创建viewController,那么你可以简单地指定这个 viewController 添加到您创建的实例变量/属性中。

You need to give your applicationDelegate class a reference to the viewController that you want to call the method on. You could do this by creating an instance variable or a property of the applicationDelegate that points to your viewController that you want to be able to call the method on. If you create your viewController in the init method of your appDelegate, or in your applicationDidLoad: method, then you can simply assign this viewController to the instance variable/property that you've created.

这篇关于来自appdelegate的viewcontroller中的访问方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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