> On Oct 7, 2015, at 11:08 PM, Graham Cox <[email protected]> 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 protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]