在 AppDelegate 中调用函数?函数、AppDelegate

由网友(提笔写情书)分享简介:按照 Cocos2d 中的 UITextField 示例中的解决方案(实际上是投票最高的答案),除了这条线,我设法做到了Following the solution (the highest-voted answer actually) at UITextField Example in Cocos2d, I man...

按照 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];
阅读全文

相关推荐

最新文章