Re: function cannot change buttons behavior
Re: function cannot change buttons behavior
- Subject: Re: function cannot change buttons behavior
- From: Quincey Morris <email@hidden>
- Date: Sat, 13 Mar 2010 20:52:15 -0800
On Mar 13, 2010, at 19:48, Marx Bievor wrote:
> - (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];
> }
You have quite a number of problems in the code you posted, but let's start with (what seems to be) the most basic.
You don't quite say, but you imply that this code is in your Controller class. So 'awakeFromNib' will get invoked on an *existing* instance of the class. (We don't know where it comes from, because you don't say -- maybe it's in a nib file.) So there's absolutely no reason why you would want to create a *second* instance of the Controller class ('cont = [[Controller alloc] init];'). Further, the outlets of the second instance (like increaseButton and decreaseButton) are *not* going to be connected to anything, because of the way you created it. Further, the other instance variables of the second instance (like polygon, polygonAngle, etc) are all going to be nil because you never set them to anything. (You only set those in the first instance.)
At the very least, it looks like you need to get rid of the 'cont' instance variable. More fundamentally, you also need to clarify your understanding of:
classes vs instances
how/when/why awakeFromNib gets invoked
how outlets get established
the target/action mechanism
_______________________________________________
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