In my program I am trying to set a value for bucket1&2 that is then outputted to a label
in previous actions I am setting a value for bucket1 and bucket2, that has been outputted to a label and when I push the button “bucket1trans” I want it to use the previous values to make a new value for bucket2, then output it to a label
What I’ve done is below
int bucket1;
int bucket2;
-(IBAction)bucket1trans:(id)sender{
bucket2 = bucket2+bucket1;
label2.text = [NSString stringWithFormat:@"%d", bucket2];
}
I am not sure if I should be using int as my program doesn’t seem to remember the previous that was set for my int.
the code you have shown isn’t sufficient for debugging what the problem is.
But the general solution are:
1) use a static variable for your bucket variables.
For Ex:
2) If you want to use the same value over the program, define it in the appDelegate and access it using the shared instance of the appDelegate of your program.
In your appDelegate, you need to synthesize the variable in order to access it using . operator.
For Example:
in your appDelegate.h file,
in your appDelegate.m