1

これは int でできる最も簡単なことのようですが、その方法を示すものは何も見つかりません。グーグルを試してみましたが、何百万ものヒットがあり、そのすべてが理解しようとしているものよりもはるかに詳細です.

私がしたいのは整数を持ち、何かが起こると(ボタンを押す、画像が移動するなど)、この整数に1を追加して別のメソッドを持ち、呼び出されたときに整数をチェックし、それに応じていくつかのアクションの1つを実行することです値について。

int に 1 を追加する以外は、これをすべて行う方法を知っていますか?

これはあなたたちにとって馬鹿げた質問に違いないことはわかっています。

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 プロパティを追加する必要があります。次に、各アクションの最初のステップとして、そのプロパティに 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 に答える