在 AppDelegate 中调用函数?

Call a function in AppDelegate?(在 AppDelegate 中调用函数?)
本文介绍了在 AppDelegate 中调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照 Cocos2d 中的 UITextField 示例中的解决方案(实际上是投票最高的答案),除了这条线,我设法做到了

Following the solution (the highest-voted answer actually) at UITextField Example in Cocos2d, I managed to do it except the line

[[[UIApplication sharedApplication] delegate] specifyStartLevel];

我已将它放在我的场景中,我收到以下警告:

I have placed it in my scene, I get this warning:

找不到实例方法-specifyStartLevel"(返回类型默认为id")

这是为什么呢?我显然在我的 AppDelegate 的标头和实现中定义了 -specifyStartLevel ...

Why is that? I clearly have -specifyStartLevel defined in the header and implementation of my AppDelegate...

编辑:specifyStartLevel

#import <UIKit/UIKit.h>

@class RootViewController;

@interface AppDelegate : NSObject <UIApplicationDelegate,UITextFieldDelegate> {
    UIWindow            *window;
    UITextField *levelEntryTextField;
    RootViewController  *viewController;
}
- (void)specifyStartLevel;
@property (nonatomic, retain) UIWindow *window;

@end

及实施:

- (void)specifyStartLevel
{
    [levelEntryTextField setText:@""];
    [window addSubview:levelEntryTextField];
    [levelEntryTextField becomeFirstResponder];    
}

推荐答案

现在,你的类对你的委托方法一无所知.您需要将您的委托导入您的实现,而不是您的接口(以避免循环导入).

Right now, your class doesn't know anything about your delegate's methods. You need to import your delegate into your implementation, not your interface (to avoid cycled imports).

例如,

#import "AppDelegate.h"

然后您应该将嵌套方法调用中返回的委托转换为您的委托类型.例如:

Then you should cast the returned delegate in your nested method call to be your delegate type. For example:

[(AppDelegate *)[[UIApplication sharedApplication] delegate] specifyStartLevel];

这篇关于在 AppDelegate 中调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
HTTPS request using volley(使用 volley 的 HTTPS 请求)