问题描述
按照 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 中调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!