Re: NSTextField subclass needs cell subclass as well - how?
Re: NSTextField subclass needs cell subclass as well - how?
- Subject: Re: NSTextField subclass needs cell subclass as well - how?
- From: Malayil George <email@hidden>
- Date: Thu, 08 Oct 2015 18:10:04 +0530
Hi,
I've set the cellClass in the +load() method (on the textfield subclass)
using setCellClass under mavericks. If memory serves me right, it set the
cell in yosemite as well. I was however, creating my cells in code as well.
If you are coding in objective-c, then you might be able to set it there
(it doesn't seem to be available in Swift).
Regards
George
On Thu, Oct 8, 2015 at 12:08 PM, Charles Srstka <email@hidden>
wrote:
> > 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
>
_______________________________________________
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