调用AppDelegate中的函数? [英] Call a function in AppDelegate?

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

问题描述

Cocos2d中的TextField示例中,遵循解决方案(实际上是得票最高的答案)除了

Following the solution (the highest-voted answer actually) at TextField 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')

Instance method '-specifyStartLevel' not found (return type defaults to 'id')

为什么?我明显有 -specifyStartLevel 在我的AppDelegate的头部和实现中定义...

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

编辑 specifyStartLevel的声明

Edit: Declaration of 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中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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