我是新的Objective-C,我有一個問題。我不明白我的錯誤在哪裏。Objective-C訪問另一個類的計數器
櫃檯告訴我,該值是0
我有一個遊戲類最多的時間,這裏是一個計數器。一段時間後,遊戲停止屏幕切換到End類。而在最後一堂課,我想打印出分數。但它不起作用。
Game.h
@interface Game : CCLayer
{
int counter;
}
@property (readwrite, nonatomic) int counter;
+(int)returnCounter;
@end
Game.m
@implementation Game
@synthesize counter;
-(void)methodForMyCounter{
counter++;
}
+(int)returnCounter{
return counter;
}
End.h
End.m
@implementation
-(void)getCounter{
//here i want to print out the counter
}
獲取一個指向其他類的實例的指針。使用它來訪問計數器屬性。 – 2013-05-02 15:03:47