2016-06-15 3 views
-1

私はスタンフォードコースを始めましたカードゲーム「Machismo」を構築しました 次のコードをビルドして実行していますが、 1の代わりに4ずつ増分します。インクリメント++は1の代わりに4を追加していますObjective C Xcode

#import "CardGameViewController.h" 

@interface CardGameViewController() 
@property (weak, nonatomic) IBOutlet UILabel *flipsLabel; 
@property (nonatomic) int *flipCount; 
@end 

@implementation CardGameViewController 

- (void) setFlipCount:(int *) flipCount { 
    _flipCount = flipCount; 
    self.flipsLabel.text = [NSString stringWithFormat:@"Flips: %d", (int) self.flipCount]; 
} 

    enter code here 
- (IBAction)touchCardButton:(UIButton *)sender { 
    if ([sender.currentTitle length]) { 
     [sender setBackgroundImage:[UIImage imageNamed:@"cardback"] 
          forState:UIControlStateNormal]; 
     [sender setTitle:@"" forState:UIControlStateNormal]; 
    }else { 
     [sender setBackgroundImage:[UIImage imageNamed:@"cardfront"] 
          forState:UIControlStateNormal]; 
     [sender setTitle:@"A♣︎" forState:UIControlStateNormal]; 
    } 
    self.flipCount++; // << HERE IS THE INCREMENT << 

} 


@end 

答えて

4

あなたはポインタのインクリメント(指示先のサイズによってインクリメントされ、およびsizeof(int型)== 4をお使いの場合)、それは印刷のためにint型にキャストされています。代わりにintをインクリメントする必要があります。

関連する問題