0
我需要通過從InGameLayer到AppDelegate中的數組訪問數組,所以這裏就是我在InGameLayer.h無法通過單
@interface InGameLayer : CCLayer
@property (nonatomic, strong) CCArray *heroArray;
+(InGameLayer *)sharedInGameLayer;
在InGameLayer.m
static InGameLayer* sharedInGameLayer;
+(InGameLayer*)sharedInGameLayer
{
if (sharedInGameLayer == nil)
{
sharedInGameLayer = [[self alloc] init];
}
return sharedInGameLayer;
}
//add Object if the button is tapped
- (void)PlayerButton1Tapped:(id)sender
{
CCSprite *hero =[CCSprite spriteWithFile:@"hero.png"];
[_heroArray addObject:hero];
}
做
in AppDelegate.m
-(void) applicationDidEnterBackground:(UIApplication*)application
{
CCArray *heroArray = [InGameLayer sharedInGameLayer].heroArray;
CCLOG(@"array = %d", heroArray.count);
}
問題在於array = 0,無論有多少對象添加到heroArray中。 請幫我解決這個問題。預先感謝您的時間。
你好,是的,我有我的初始化數組像這樣在我的init方法。問題是我沒有在init方法中添加我的Object。我想要用戶通過單擊按鈕添加對象。對象永遠不會傳遞給AppDelegate(該數組在AppDelegate中爲零)。你能否建議一種方法來做到這一點?謝謝您的回覆 – user1817517 2013-03-06 15:26:53