计算一个方法在 Cocoa-Touch 中被调用的次数?

Count the number of times a method is called in Cocoa-Touch?(计算一个方法在 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 中被调用的次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)