Reputation: 4282
I'm doing the HelloPoly example from the Stanford class and trying to disable the increase/decrease buttons when appropriate
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
@interface Controller : NSObject {
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet UILabel *nameLabel;
IBOutlet UILabel *angleLabel;
IBOutlet UILabel *minSidesLabel;
IBOutlet UILabel *maxSidesLabel;
IBOutlet PolygonShape *polygonShape;
}
-(IBAction)decrease:(id)sender;
-(IBAction)increase:(id)sender;
-(void)updateUI;
@end
and then in my Controller.m, none of the effects on the increase or decrease button take
-(IBAction)decrease:(id)sender
{
//NSLog(@"-");
polygonShape.numberOfSides--;
if (polygonShape.numberOfSides == polygonShape.minimumNumberOfSides)
decreaseButton.enabled = NO;
else
decreaseButton.enabled = YES;
self.updateUI;
increaseButton.enabled = NO;
increaseButton.highlighted = YES;
increaseButton.hidden = YES;
}
Upvotes: 2
Views: 8515
Reputation: 1092
This is how I handled it so long ago, a bit more verbose than your version but basically the same, as in the comment, check your connections in IB, and stick with YES/NO everywhere as well.
- (IBAction)decrease:(id)sender {
if ([shape numberOfSides] >= minNumberOfSides) {
[shape setNumberOfSides:[shape numberOfSides]-1];
NSLog(@"Decrease!");
}
[self updateInterface];
}
- (IBAction)increase:(id)sender {
if ([shape numberOfSides] <= maxMumberOfSides) {
[shape setNumberOfSides:[shape numberOfSides]+1];
NSLog(@"Increase!");
}
[self updateInterface];
}
- (void)updateInterface {
numberOfSidesLabel.text = [NSString stringWithFormat:@"%d", [shape numberOfSides]];
nameLabel.text = [NSString stringWithFormat:@"%@", [shape name]];
if ([shape numberOfSides] == minNumberOfSides) {
decreaseButton.enabled = NO;
}
else {
decreaseButton.enabled = YES;
}
if ([shape numberOfSides] == maxNumberOfSides) {
increaseButton.enabled = NO;
}
else {
increaseButton.enabled = YES;
}
}
Upvotes: 2