Hi all,

I have two functions increase and decrease which control the number of sides of 
a polygon. I want to call a - (void)function that disables the buttons if the 
current number of sides are equal to the maximum number of sides.

1) One problem is that "button.enabled=YES/NO" does not get called. If I put 
this line into the decrease/increase function it works fine. But I don't want 
to copy-paste the code, so I thought I can put this into my updateInterface 
function.

2) Another problem is that somehow the function "cannot" change the ivars 
values.. Again, if I put the code in the increase, decrease functions I have no 
problems.

3) And lastly I'm not sure if I'm doing it "correctly". As updateInterface is a 
method declared in my controller class, polygon cannot call it. I use an 
"Controller" object to invoke the updateInterface function. Due to the fact 
that the function must change some ivars, I cannot use a class function... I 
think it could be the reason why it doesn't work the way it should, but at this 
point I don't see why...

I hope you can help me understand the issue here. I'm new to mac programming.

CODE:

- (void)awakeFromNib{
        cont = [[Controller alloc] init];
        polygon = [[PolygonShape alloc] initWithNumberOfSides:5 
minimumNumberOfSides:3                  maximumNumberOfSides:12];
        numberOfSidesLabel.text=[NSString stringWithFormat:@"%d %d 
%d",polygon.numberOfSides,           polygon.minimumNumberOfSides, 
polygon.maximumNumberOfSides];
        polygonAngle.text=[NSString stringWithFormat:@"%f %f", 
polygon.angleInDegrees,                  polygon.angleInRadians];
        polygonName.text=[NSString stringWithFormat:@"%@", polygon.name];
}

- (IBAction)decrease{
        polygon.numberOfSides-=1;
        [cont updateInterface:polygon];
}

- (IBAction)increase{
        polygon.numberOfSides+=1;
        [cont updateInterface:polygon];
}

- (void)updateInterface:(id)sender{

        numberOfSidesLabel.text=[NSString stringWithFormat:@"%d %d 
%d",polygon.numberOfSides,           polygon.minimumNumberOfSides, 
polygon.maximumNumberOfSides];
        polygonAngle.text=[NSString stringWithFormat:@"%f %f", 
polygon.angleInDegrees,                  polygon.angleInRadians];
        polygonName.text=[NSString stringWithFormat:@"%@", polygon.name];
        
        if ([sender numberOfSides]==[sender maximumNumberOfSides]) {
                [increaseButton setEnabled:NO];
                increaseButton.enabled=NO;
        }else if ([sender numberOfSides]==[sender minimumNumberOfSides]) {
                decreaseButton.enabled=NO;
        }else {
                increaseButton.enabled=YES;
                decreaseButton.enabled=YES;
        }
}

THANKS A LOT!
-M_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to