Call a function in 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 中调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 AppDelegate 中调用函数?


基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01