Re: Cloning IB objects
Re: Cloning IB objects
- Subject: Re: Cloning IB objects
- From: publiclook <email@hidden>
- Date: Mon, 28 Jul 2003 13:06:34 -0400
On Monday, July 28, 2003, at 03:36 AM, Fred Klein wrote:
Hi
What is the best way to clone IB objects (NSButton, NSTextView, etc)?
I would like to use IB objects as prototype to programmatically create
new
instances of these and display them underneath of the first instance
(similar
to Mail where one can add criteria to rules).
I am about to code a category for some of these (NSButton for
instance) that
would provide a clone: method. But that's tedious. Any other way how
to do that?
I think this is how IB actually copies objects when you use copy and
paste in IB. A nib is mostly composed of archived objects.
NSData *anyArchiveObjectGraph = [NSArchiver
archivedDataWithRootObject:someObject];
id copyOfArchivedObjectGraph = [NSUnarchiver
unarchiveObjectWith
Data:anyArchiveObjectGraph];
Use code like above copy a view and all of its interconnected sub-views
preserving all relationships and connections. Then insert the copy in
the view hierarchy somewhere. That is how you clone.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.