Re: Copying an NSPopUpButton
Re: Copying an NSPopUpButton
- Subject: Re: Copying an NSPopUpButton
- From: j o a r <email@hidden>
- Date: Sun, 12 Aug 2007 17:50:43 +0200
On 12 aug 2007, at 17.43, Martin Linklater wrote:
I want to get and set the items in the NSPopUpButton from the Cpu
class, so I have added a pointer along with it's associated setter
and getter. I have tried to create a set method as follows:
// cpu.m
-(void)setButton:(NSPopUpButton*)button
{
[myButton release];
myButton = [button copy];
[button release];
}
but the compiler complains that there is no 'copy' method for
NSPopUpButton. Since this class does not conform to NSCopying
that's fair enough. But how then do I copy the pointer while
maintaining reference counting etc. ?
In this case you don't want to copy the button. If you create a copy
and update it, the original pop-up button in the UI will of course
not be updated to reflect those changes. What you want is to just
have a reference to the original pop-up, something like this:
- (void) setButton:(NSPopUpButton*) button
{
[myButton autorelease];
myButton = [button retain];
}
And don't forget to balance the retain in your dealloc method:
- (void) dealloc
{
[myButton release];
// Other release statements
[super dealloc];
}
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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