• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
function cannot change buttons behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

function cannot change buttons behavior


  • Subject: function cannot change buttons behavior
  • From: Marx Bievor <email@hidden>
  • Date: Sun, 14 Mar 2010 04:48:25 +0100

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: function cannot change buttons behavior
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: How to show a progress without multithreading?
  • Next by Date: Re: How to show a progress without multithreading?
  • Previous by thread: Re: How to show a progress without multithreading?
  • Next by thread: Re: function cannot change buttons behavior
  • Index(es):
    • Date
    • Thread