从类中调用AppDelegate方法 [英] Call AppDelegate Method from Class

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

问题描述

基本上,我需要从我的一个视图控制器类中调用AppDelegate中的一个方法.

Basically, I need to call a method in my AppDelegate from one of my view controller classes.

当前,我正在执行以下操作:

Currently, I'm doing the following:

myAppDelegate * appDelegate =(myAppDelegate *)[[UIApplication sharedApplication]委托];

[appDelegate doMethod];

并在类.m文件顶部包含myAppDelegate.h:

And including the myAppDelegate.h at the top of the .m file of the class:

#import"myAppDelegate.h"

当我运行它时,一切正常...

When I run it, everything works...

但是我收到以下警告:

警告'myAppDelegate'可能不响应'-doMethod'

还有另一种方法可以引用应用程序委托吗?

Is there another way that I should reference the app delegate?

非常感谢您提前提供帮助.

Thanks for any help in advance.

已修复:

FIXED:

我要做的就是在AppDelegate的.h文件中声明该方法:

All I had to do was declare the method in the .h file of the AppDelegate:

-(void)doMethod;

推荐答案

添加到Marks注释中.是在appDelegate头文件中声明的-((void)doMethod; ),还是在您尝试从以下位置调用该方法的文件中导入的appDelegate.h文件:)

adding to Marks comment. Is the -(void) doMethod; declared in the appDelegate header file and is the appDelegate.h file imported in the file you try to call the method from:)

对不起,应该首先把它作为答案,所以这个问题看起来并没有得到解答:/

Sorry should have put it in as an answer in the first place, so the question does not look unanswered :/

这篇关于从类中调用AppDelegate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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