• 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: NSTextField subclass needs cell subclass as well - how?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField subclass needs cell subclass as well - how?


  • Subject: Re: NSTextField subclass needs cell subclass as well - how?
  • From: Charles Srstka <email@hidden>
  • Date: Thu, 08 Oct 2015 01:38:26 -0500

> On Oct 7, 2015, at 11:08 PM, Graham Cox <email@hidden> wrote:
>
> I’ve tried swapping out the text field’s cell by creating a subclass and copying all of the original settings into it. Unfortunately that doesn’t work - just copying across the state isn’t enough to make the replacement cell look and act like the original text field cell, for some reason - presumably there’s some order-dependent setup or other hidden stuff in the ‘real’ text field cell that I can’t get at.

Did you try fully copying the state by using NSKeyedArchiver? That should work to replicate all the setup the cell would have done when unarchiving from the nib:

+ (nullable NSCell *)cellOfClass:(nonnull Class)cellClass byCloningCell:(nonnull NSCell *)cell {
    if (![cellClass isSubclassOfClass:cell.class]) {
        return nil;
    }

    NSMutableData *data = [NSMutableData new];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

    [cell encodeWithCoder:archiver];
    [archiver finishEncoding];

    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    NSCell *newCell = [[cellClass alloc] initWithCoder:unarchiver];

    [unarchiver finishDecoding];

    return newCell;
}

Charles

_______________________________________________

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: NSTextField subclass needs cell subclass as well - how?
      • From: Malayil George <email@hidden>
References: 
 >NSTextField subclass needs cell subclass as well - how? (From: Graham Cox <email@hidden>)
 >Re: NSTextField subclass needs cell subclass as well - how? (From: Graham Cox <email@hidden>)
 >Re: NSTextField subclass needs cell subclass as well - how? (From: Quincey Morris <email@hidden>)
 >Re: NSTextField subclass needs cell subclass as well - how? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: NSTextField subclass needs cell subclass as well - how?
  • Next by Date: iOS Keyboard Woes
  • Previous by thread: Re: NSTextField subclass needs cell subclass as well - how?
  • Next by thread: Re: NSTextField subclass needs cell subclass as well - how?
  • Index(es):
    • Date
    • Thread