• 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
Substituting instance of cell subclass for instance of superclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Substituting instance of cell subclass for instance of superclass


  • Subject: Substituting instance of cell subclass for instance of superclass
  • From: James Walker <email@hidden>
  • Date: Fri, 11 Nov 2016 17:34:03 -0800

I want to replace (for example) an instance of NSButtonCell with an instance of my own subclass of NSButtonCell on the fly. Now, I know that's not a common thing to want to do; normally, you'd edit the nib to use whatever cell class you want. But I'd like to be able to do it to an NSAlert, for which I don't have a nib.

So, my thought was to first make an instance of my cell class that copies all the state of the NSButtonCell instance, and then use -[NSControl setCell:]. The documentation on setCell: does say: "Use this method with great care as it can irrevocably damage the affected control; specifically, you should only use this method in initializers for subclasses of NSControl."
Anyone know what kind of damage we're talking about?

Anyway, as far as copying the cell state, I tried this:

- (id) initCopyingBaseCell: (NSButtonCell*) oldCell
{
	NSData* archive = [NSKeyedArchiver
		archivedDataWithRootObject: oldCell];
	NSKeyedUnarchiver* coder = [[[NSKeyedUnarchiver alloc]
			initForReadingWithData: archive] autorelease];

	self = [super initWithCoder: coder];
	if (self != nil)
	{

	}
	return self;
}

However, the new cell has failed to copy much of the state of the old one. Things like title, font, target, action, bezelStyle... I can manually copy anything that I notice is missing, but I'm just wondering why the keyed archiver approach here doesn't work.
_______________________________________________

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: Substituting instance of cell subclass for instance of superclass
      • From: Jonathan Mitchell <email@hidden>
    • Re: Substituting instance of cell subclass for instance of superclass
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Make WatchKit app show local notification
  • Next by Date: Re: Substituting instance of cell subclass for instance of superclass
  • Previous by thread: Re: Make WatchKit app show local notification
  • Next by thread: Re: Substituting instance of cell subclass for instance of superclass
  • Index(es):
    • Date
    • Thread