Count the number of times a method is called in Cocoa-Touch?(计算一个方法在 Cocoa-Touch 中被调用的次数?)
问题描述
我有一个小应用程序,它使用 cocos2d 运行游戏的四个关卡",其中每个关卡都完全相同.第四关运行后,我想显示一个结束游戏的场景.我能够处理这个问题的唯一方法是制作四种方法,每个级别一个.毛.
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?
推荐答案
你能不能每次调用你的方法时只增加一个实例变量整数?
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:
在你的头文件中,添加一个整数作为实例变量:
In your header file, add an integer as a instance variable:
@interface MyObject : NSObject {
UIInteger myCounter;
}
然后在你的方法中,增加它:
And then in your method, increment it:
@implementation MyObject
- (void)myMethod {
myCounter++;
//Do other method stuff here
if (myCounter>3){
[self showEndGameScene];
}
}
@end
这篇关于计算一个方法在 Cocoa-Touch 中被调用的次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:计算一个方法在 Cocoa-Touch 中被调用的次数?


基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01