Ok so I am like one day into learning objective c. I know this is a really basic question, but it will help me with my learning greatly. So the code is just a basic counter, but I want to add something to it so when the counter reaches a certain number, a different message appears. I have tried many different things but I failed. Thanks in advance.
#import "MainView.h"
@implementation MainView
int count = 0;
-(void)awakeFromNib {
counter.text = @"count";
}
- (IBAction)addUnit {
if(count >= 999) return;
NSString *numValue = [[NSString alloc] initWithFormat:@"%d", count++];
counter.text = numValue;
[numValue release];
}
- (IBAction)subtractUnit {
if(count <= -999) return;
NSString *numValue = [[NSString alloc] initWithFormat:@"%d", count--];
counter.text = numValue;
[numValue release]; {
}
}
First of all, instead of putting the count as a global variable, it’s more appropriate to put it in your interface instead. And regarding the question you have, your code should be changed to something like this.
Then you can change your other method to something similar.