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

[[UIApplication sharedApplication] delegate]問題を解決するには、呼び出しをアプリケーション デリゲートの型にキャストするだけです。したがって、その呼び出しを行うたびに、次のように結果をキャストします。

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

その後、デリゲートからメソッドを呼び出してプロパティにアクセスできます。

((YourAppDelegateClass*)[[UIApplication sharedApplication] delegate]).gameMode = 
    @"someGameMode";
于 2012-07-16T15:21:47.113 に答える
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 に答える