• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How can I copy/duplicate an existing NSTextField?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I copy/duplicate an existing NSTextField?


  • Subject: Re: How can I copy/duplicate an existing NSTextField?
  • From: Tito Ciuro <email@hidden>
  • Date: Fri, 24 Nov 2006 20:25:27 -0800

Hello Chris and Mark,

Even though it's a bit more work, Chris' suggestion makes more sense to me: I can setup the UI exactly the way I want and then instantiate it easily without having to add complex code to manage it. I think I'll take this route.

Thanks a lot for your quick response,

-- Tito

On Nov 24, 2006, at 6:45 PM, Chris Hanson wrote:

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.

This technique will also make it a lot easier to do test-driven development of your human interface: You'll be able to write one clear & simple set of unit tests to specify how the views in your nib file will be wired to their controller, and an orthogonal set of tests that your human interface set-up and layout code will instantiate and configure the proper controllers.

  -- Chris


_______________________________________________

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


References: 
 >How can I copy/duplicate an existing NSTextField? (From: Tito Ciuro <email@hidden>)
 >Re: How can I copy/duplicate an existing NSTextField? (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: NSImage ignoring interpolation: Is this a bug?
  • Next by Date: Re: Re: why there is a memory leak in this method?
  • Previous by thread: Re: How can I copy/duplicate an existing NSTextField?
  • Next by thread: Re: How can I copy/duplicate an existing NSTextField?
  • Index(es):
    • Date
    • Thread