Re: How can I copy/duplicate an existing NSTextField?
Re: How can I copy/duplicate an existing NSTextField?
- Subject: Re: How can I copy/duplicate an existing NSTextField?
- From: Matt Neuburg <email@hidden>
- Date: Sat, 25 Nov 2006 08:34:30 -0800
- Thread-topic: How can I copy/duplicate an existing NSTextField?
On Fri, 24 Nov 2006 18:45:43 -0800, Chris Hanson <email@hidden> said:
>On Nov 24, 2006, at 3:54 PM, Tito Ciuro wrote:
>
>> I have an NSTextField connected to an IBOutlet. This text field
>> contains certain properties, such as font, size, color, and other
>> attributes. I need to replicate this field programatically several
>> times, in order to add it to a view. I thought I could do something
>> like:
>>
>> NSTextField *myField = [templateField copy];
>>
>> Unfortunately, this raises an exception. So my question is: how can
>> I replicate a NSTextField retaining its attributes?
>
>Rather than replicating a text field, set up a nib containing a bare
>NSView that contains a text field and has a File's Owner that
>represents a controller object for the view. Then just instantiate
>this nib multiple times (one per field you need) when creating your
>human interface on the fly.
>
>This technique will be a lot more general and a lot more flexible than
>doing all of the instantiation of your user interface in code, and
>also a lot cleaner than instantiating one field in a nib file and then
>having the knowledge that it needs to be "cloned" in your code.
But pay attention to memory management considerations: a view object loaded
from a nib is not autoreleased, so if you don't manage memory correctly,
you'll leak text fields out the wazoo (a technical term). m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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