0

使用 cocos2d 的游戏运行良好,但是使用这个新的 xcode 4.3.3 运行不佳。它显示此错误:

Property 'gameMode' not found on object of type 'id<UIApplicationDelegate>'

在这部分代码中:

-(void)oneDuckClicked:(id)sender{
    [[UIApplication  sharedApplication] delegate].gameMode = [NSString stringWithFormat:@"OneDuck"];
    [[[UIApplication sharedApplication] delegate] createDifficultySelectionScene];
}

-(void)twoDucksClicked:(id)sender{
    [[UIApplication  sharedApplication] delegate].gameMode = [NSString stringWithFormat:@"TwoDucks"];
    [[[UIApplication sharedApplication] delegate] createDifficultySelectionScene];
}

有任何想法吗?

4

2 回答 2

1

在 appDelegate 类中添加 gameMode 成员。

@interface AppDelegate : NSObject
{
    NSString *gameMode;
    …..
    …..
}

@property (nonatomic, retain) MyAchievement *Achievement;

@end


@implementation AppDelegate

@synthesize gameMode;

……..
……..
……..
@end

像这样访问:

AppDelegate *App = (AppDelegate *)[[UIApplication sharedApplication] delegate] ;
App.gameMode = @"MyGameMode";
于 2012-07-16T15:24:05.283 回答
1

要解决您的问题,您只需将调用转换[[UIApplication sharedApplication] delegate]为应用程序委托的类型。因此,每次您进行该调用时,都将结果转换为:

((YourAppDelegateClass*)[[UIApplication sharedApplication] delegate])

然后你可以从你的委托中调用方法和访问属性:

((YourAppDelegateClass*)[[UIApplication sharedApplication] delegate]).gameMode = 
    @"someGameMode";
于 2012-07-16T15:21:47.113 回答