1

似乎这应该是你可以用 int 做的最简单的事情,但我似乎找不到任何显示如何做到这一点的东西。试过谷歌,但我得到了一百万次点击,所有这些都比我试图理解的更深入。

我想要做的是有一个整数,当发生某些事情时(按钮按下,图像移动,等等)我想给这个整数加 1 并有一个单独的方法,当它被调用时,检查整数并根据几个动作之一执行关于价值。

除了将 1 添加到 int 之外,我知道如何执行所有这些操作?

我知道这对你们来说一定是一个疯狂的愚蠢问题,有人愿意给我一根骨头吗?

4

3 回答 3

2
int i = 4;
i++;

那是你要找的吗?

于 2012-09-01T08:05:59.403 回答
2

在 .h 文件中声明 int 索引

现在点击按钮:

 -(void)btnClicked:(id)sender
 {
     index++;
 }

然后移动任何其他方法图像

index++;

现在执行如下操作:

-(void)performAction:(int)index
{
   switch(index)
   {
      //make case depending on number
      case : 1
      {
          // do something here on index 1
      }
      break;
      .....
      .....
      .....
      default
      {
          // do something here if not that index 
      }
      break;

   }


}
于 2012-09-01T08:06:54.707 回答
0

您应该向 UIViewController 添加一个 NSUInteger 属性,在该 UIViewController 中发生您要计算的操作。然后作为每个操作的第一步,您可以向该属性添加 1。

@interface MyViewController extends UIViewController
@property (nonatomic) NSUInteger actionCounter;
@end

@implementation MyViewController
@synthesize actionCounter;

//in your actions here, add one to actionCounter
-(void) IBAction doSomething{
    self.actionCounter++;

    //do the actual action here
}

//in your check method, read the actionCounter value and do something
-(void) checkActionCount{
    if(self.actionCounter => 1){
        NSLog(@"User did something");
    }
}

@end
于 2012-09-01T08:06:07.253 回答