I can't see any way to copy an NSView and create an identical NSView object. I see google hits about "use an NSData" but I don't understand that.
+4
A:
To straight up "copy" an NSView, the view has to implement the NSCopying
protocol. Unfortunately, NSView does not.
Fortunately, it does implement the NSCoding
protocol, which means we can still duplicate a view like:
NSData * archivedView = [NSKeyedArchiver archivedDataWithRootObject:myView];
NSView * myViewCopy = [NSKeyedUnarchiver unarchiveObjectWithData:archivedView];
And voilá! You now have a duplicate of myView
.
Dave DeLong
2010-06-24 05:30:40
Note that if you subclass, you'll need to implement archiving support. The docs know all.
bbum
2010-06-24 07:25:57
In every case that I subclass - even when I don't have data added but only a couple methods?
Nektarios
2010-06-24 16:09:45
Nektarios: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmImplementCopy.html
Peter Hosey
2010-06-25 07:59:44