• 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: Chris Hanson <email@hidden>
  • Date: Fri, 24 Nov 2006 18:45:43 -0800

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


  • Follow-Ups:
    • Re: How can I copy/duplicate an existing NSTextField?
      • From: Tito Ciuro <email@hidden>
References: 
 >How can I copy/duplicate an existing NSTextField? (From: Tito Ciuro <email@hidden>)

  • Prev by Date: NSImage ignoring interpolation: Is this a bug?
  • Next by Date: Re: Repositioning an NSTextFieldCell?
  • 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