I want a UIAlertView to popup if the user doesn’t have enough points to purchase an upgrade. So far I have this code to spend points to get the upgrade. If the upgrade costs 300 points, and the user only has 150, I would like the UIAlertView to calculate the amount needed and say something like, “Sorry, you need 150 more points to buy this upgrade”. Here’s my code. (‘mag’ and ‘score’ are both ints.)
-(int)mag {
return [[NSUserDefaults standardUserDefaults] integerForKey:kMagDefaultsKey];
}
-(int)score {
return [[NSUserDefaults standardUserDefaults] integerForKey:kScoreDefaultsKey];
}
-(void)setMag:(int)value {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:kMagDefaultsKey];
}
-(void)setScore:(int)value {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:kScoreDefaultsKey];
}
-(void)plusFiveMag:(id)sender {
self.mag = self.mag + 5;
self.score = self.score - 300;
}
Try somethin like this…