iphone - How to add up a value when a button pressed -
The last time I asked when a button is pressed
- (IBAction) AddTap: (id) this; Now call me tapCount ++; was used to use (tapacount is an int type variable) button was pressed to add 1 time. However, I think the value remains the same, no matter how many times I pressed it.
I want to be a popcount 1 if I press the button once, and make it 2, if I press the button
in detail:
The pass player is a class named, which is called a member of the result of int takpcount and int
When the button is pressed each time, a value will be added to the tapacount, and the value will be displayed at the end (When Game & Say)
For now, whenever I want to check it A. I use NSLog the value remains the same.
Player.h
@class TappingViewController; @ Interface player: NSBK {NSSTING * name; Int Takpank; Full result; } @property (nanatomic, assign) NSString * name; @protty (nanatomic, assign) int tapacount; @property (nonatomic, assigned) integer results; @end TappingViewController.h
@interface TappingViewController: UIViewController {} - (IBAction) addTap: (id) this; @end TappIngViewController.m
#import "Tapping Video Controller." #import "Player.h" @ class player; Int Takpank; @implementation TappingViewController - (id) initWithNibName: (NSString *) nibNameOrNil Bundle: (NSBundle *) nibBundleOrNil {self = [super initWithNibName: nibNameOrNil Bundle: nibBundleOrNil]; If (self) {} returns back to himself; } / * - (zero) loadview {} * / - (zero) viewDidload {player * a player = [[player light] init]; NSLog (@ "tapcount:% d", aPlayer.tapCount); [Super viewedload]; } - (IBAction) addTap: (ID) sender; {NSLog (@ "BeforeL% d", Tapcount); TapCount ++; NSLog (@ "after:% d", tapacount); } / * - (bool) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {return (interfaceOrientation == UIInterfaceOrientationPortrait); } * / - (zero) did risive memorianising [[super dreadrevimmy warning]; } - (zero) viewDidUnload {} - (zero) dealloc {[super dealloc]; } addTap: in the You can see the tapping view Referring to the controller's tapacount which is different from the player's tapCount , even if they have the same name, they are different, then you will see the aPlayer Need to reference the property of taxcount : aPlayer.tapCount ++; However there is no scope of the aPlayer in the addTap: method. The only place you can currently reference in aPlayer is in the viewDidLoad method. You need to change this: (You do not need this comments which I have added to indicate changes)
TappingViewController.h
@class player; // ** You have imported player squares in .m file, so if you use player class in the header then you have to add it as a forward class. @ Interface tapping VICI controller: UIViewController {Player * aPlayer; // ** This is an example variable (ivar) so that you can access it in the implementation (.m file) in any way, although you still need to put something in this ivar (see ViewDidLoad) ** } // ** If you want you can add an asset to a player, but remember to do memory management properly - (IBAction) addTap: (ID) sender; @end TappIngViewController.m
#import "tapping Vikwa controller" #import "Player.h" // ** Forward rid of the class, you ** // ** tapCount rid of that were ** @implementation TappingViewController up as it is imported - initWithNibName (ID): (NSString *) nibNameOrNil Bundle: (NSBundle *) nibBundleOrNil {self = [super initWithNibName : NebankNineNonline Bundle: NegotiateOnline]; If (self) {} returns back to himself; } / * - (zero) load views {} * / - (zero) viewsDidload {aPlayer = [[Player Light] init]; // ** Declare the announcement of a new var ** NSLog (@ "tapcount:% d", aPlayer.tapCount); [Super viewedload]; } - (IBAction) addTap: (ID) sender; {NSLog (@ "BeforeL% d", Tapcount); APlayer.tapCount ++; // ** Player's Tapcon ** Refer to NSLog (@ "After:% d", Tapacount); } / * - (BOOL) Chahiaayutrotettointrfesorenteshn: (Uaianprfesoriynteshn) Intrfesorianteshn {return (interface Orianteshn == Uaiantrfesorenteshn Portrait); } * / - (zero) did risive memorianising [[super dreadrevimmy warning]; } - (zero) viewDidUnload {} - (zero) dealloc {[super dealloc]; } @end
Comments
Post a Comment