views:

643

answers:

1

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 = FALSE;
    else 
        decreaseButton.enabled = TRUE;

    self.updateUI;

    increaseButton.enabled = NO;
    increaseButton.highlighted = YES;
    increaseButton.hidden = YES;

}
+1  A: 

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;
}
}
Eric Schweichler
Buttons were not wired. Doh. Thank you. I hope later I learn how to wire them in code. I'm not used to all this gui programming :)also for the others, TRUE is the same as YES, and dot notation is the same as [], but thx for the attempt to help :)NSLog(@"YES == TRUE?: %d", (YES==TRUE));2010-04-08 12:29:17.860 HelloPoly[5897:207] YES == TRUE?: 1
rschmitty
Sure YES == TRUE and NO == FALSE, and you can mix them, it's just more Objective-C/Cocoa like to stick with YES NO. Glad we could help!
Eric Schweichler