• 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: NSCustomView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCustomView?


  • Subject: Re: NSCustomView?
  • From: Philip Ershler <email@hidden>
  • Date: Sat, 14 May 2005 09:30:59 -0600


On May 14, 2005, at 8:07 AM, Theodore H. Smith wrote:

How do you use NSCustomView?

I don't see any help on NSCustomView. Searching brings up this: http://developer.apple.com/cgi-bin/search.pl? q=NSCustomView&num=10&site=default_collection


If you look at the first reference that the above URL brings up, the first section says it all.

Initializing Nib File Objects

There are three types of objects you can add to a nib file: standard objects dragged from a palette into the design window; subclasses of such objects; and custom objects for which you have provided a custom subclass of NSView. To add a custom object to your user interface, you drag a Custom View object into the design window.

When you drag a standard object into the design window, Interface Builder encodes the actual class for that object, initializing the object as it builds the nib file. For custom subclasses of such objects, Interface Builder encodes the standard object but tells the archiver to swap in your custom class when the object is unarchived. These objects are also initialized when the nib file is built. Therefore, when the nib file is loaded, initWithFrame: is not called for either standard objects or custom subclasses of standard objects.

On the other hand, because the actual code for your subclass of NSView is not resident in Interface Builder, it does not encode the actual subclass when you drag a custom view object into the design window. Instead, it encodes a special object called NSCustomView that knows how to build the real custom view subclass. After NSCustomView has been instantiated by initWithCoder:, it calls alloc and initWithFrame: for the real class, and swaps in the real instance.

Therefore, if you create a custom subclass of NSView, add a Custom View object to your design window, and assign your custom subclass to that object, your initWithFrame: method will be called when the nib is loaded. For all other objects, whether standard Interface Builder objects or custom subclasses of standard objects, initWithFrame: is never called.

If you need to initialize a standard Interface Builder object (or a custom subclass of such an object) after its nib file has been loaded, create an awakeFromNib method for the object. Your awakeFromNib method is called after all the nib file’s objects have been loaded and all the connections have been set up. The order in which objects are sent the awakeFromNib message is not guaranteed.

This is really nothing you really have to worry about. But three statements contain the relevant information.



To add a custom object to your user interface, you drag a Custom View object into the design window.

For custom subclasses of such objects, Interface Builder encodes the standard object but tells the archiver to swap in your custom class when the object is unarchived.

On the other hand, because the actual code for YOUR subclass of NSView is not resident in Interface Builder, it does not encode the actual subclass when you drag a custom view object into the design window. Instead, it encodes a special object called NSCustomView that knows how to build the real custom view subclass. After NSCustomView has been instantiated by initWithCoder:, it calls alloc and initWithFrame: for the real class, and swaps in the real instance.



The Interface Builder has an icon that you can drag to your design window called Custom View. All this really does is set up the "structure" so that you can use your own subclass of NSView, that you need to create. There actually is no such thing as NSCustomView. It's just sort of a placeholder that is used to represent your "Custom NSView" (read that as subclass of NSView) in Interface Builder and the earliest stage of loading your NSView subclass when your app is run.


Phil





Which contains two pages about Java and one which doesn't even explain NSCustomView.


Is NSCustomView some kind of secret class? Is it worth using when trying to group common behaviour?

Basically, I want to have an array of controls, each of which will have a certain relationship to each other.

Visually like this:

<label><comboBox1><comboBox2><button>

And then I want to have many of these displayed vertically.

<label><comboBox1><comboBox2><button>
<label><comboBox1><comboBox2><button>
<label><comboBox1><comboBox2><button>

I was thinking, maybe the best way to do this, is to use an NSCustomView? If not, what is the best way?

--
elfdata.com/plugin/ Industrial strength string processing, made easy.

"All things are logical. Putting free-will in the slot for premises in
a logical system, makes all of life both understandable, and free."

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >NSCustomView? (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: SplitView
  • Next by Date: Re: SplitView
  • Previous by thread: Re: NSCustomView?
  • Next by thread: IB makes NSSplitView awkward to adjust
  • Index(es):
    • Date
    • Thread