计数在Cocoa-Touch中调用方法的次数? [英] Count the number of times a method is called in Cocoa-Touch?
问题描述
我有一个小应用程序,使用cocos2d运行游戏的四个级别,其中每个级别是完全相同的事情。在第四级运行后,我想显示一个结束游戏场景。我能够处理这个的唯一方法是通过制作四个方法,每个级别一个。 Gross。
I have a small app that uses cocos2d to run through four "levels" of a game in which each level is exactly the same thing. After the fourth level is run, I want to display an end game scene. The only way I have been able to handle this is by making four methods, one for each level. Gross.
我遇到这种情况几次使用cocos2d和只有基本的Cocoa框架。那么我可以计算一个方法被调用的次数吗?
I have run into this situation several times using both cocos2d and only the basic Cocoa framework. So is it possible for me to count how many times a method is called?
推荐答案
每次调用方法时,您只需增加一个实例变量integer
Can you just increment an instance variable integer every time your method is called?
我无法在注释中格式化代码,所以要详细说明:
I couldn't format the code in a comment, so to expound more:
在头文件中,添加一个整数作为实例变量: / p>
In your header file, add an integer as a instance variable:
@interface MyObject : NSObject {
UIInteger myCounter;
}
然后在方法中增加:
@implementation MyObject
- (void)myMethod {
myCounter++;
//Do other method stuff here
if (myCounter>3){
[self showEndGameScene];
}
}
@end
这篇关于计数在Cocoa-Touch中调用方法的次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!