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

Re: Substituting instance of cell subclass for instance of superclass


  • Subject: Re: Substituting instance of cell subclass for instance of superclass
  • From: Kyle Sluder <email@hidden>
  • Date: Fri, 11 Nov 2016 20:27:46 -0600

On Fri, Nov 11, 2016, at 07:34 PM, James Walker wrote:
> 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.

You also have no idea if the NSAlert is already using a custom
NSButtonCell subclass—or whether it uses NSControl at all.

Your only option here is to reimplement the alert.

--Kyle Sluder

>
> 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: James Walker <email@hidden>
References: 
 >Substituting instance of cell subclass for instance of superclass (From: James Walker <email@hidden>)

  • Prev by Date: Substituting instance of cell subclass for instance of superclass
  • Next by Date: Re: Make WatchKit app show local notification
  • Previous by thread: Substituting instance of cell subclass for instance of superclass
  • Next by thread: Re: Substituting instance of cell subclass for instance of superclass
  • Index(es):
    • Date
    • Thread