Objective c 如何在Xcode中添加int

Objective c 如何在Xcode中添加int,objective-c,xcode,integer,int,add,Objective C,Xcode,Integer,Int,Add,似乎这应该是关于最简单的事情,你可以做一个int,但我似乎找不到任何显示如何做。我尝试过谷歌,但我得到了一百万次点击,所有这些都比我试图理解的要深入得多 我想做的是有一个整数,当发生什么事情时,按下按钮,移动图像,我想给这个整数加1,并有一个单独的方法,当它被调用时,检查整数并根据值执行几个操作之一 我知道怎么做,除了在int中加1 我知道这对你们来说一定是个愚蠢的问题,有人愿意扔我一根骨头吗 int i = 4; i++; 这就是你要找的吗 这就是你要找的吗 您应该在UIViewContro

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

我想做的是有一个整数,当发生什么事情时,按下按钮,移动图像,我想给这个整数加1,并有一个单独的方法,当它被调用时,检查整数并根据值执行几个操作之一

我知道怎么做,除了在int中加1

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

int i = 4;
i++;
这就是你要找的吗


这就是你要找的吗

您应该在UIViewController中添加一个NSUInteger属性,在该属性中要计算的Acton发生。然后,作为每个操作的第一步,您可以向该属性添加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

您应该在UIViewController中添加一个NSUInteger属性,在该属性中发生要计数的Acton。然后,作为每个操作的第一步,您可以向该属性添加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

在.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;

   }


}

在.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;

   }


}

普莱斯,你这个摇滚老兄!索引++;为我做的,我试着做索引+1;此外,开关部分将帮助我清理所有我计划使用的if语句。谢谢你,伙计!普莱斯,你这个摇滚老兄!索引++;为我做的,我试着做索引+1;此外,开关部分将帮助我清理所有我计划使用的if语句。谢谢你,伙计!是的,就是那个,上面的答案被接受了,因为它可能会帮助更多的人,但你坚持住了。是的,就是那个,上面的答案被接受了,因为它可能会帮助更多的人,但你坚持住了