IB Palettes?

  • I'm reading the NSView docs, and I got to the section on using IB. It
    says, "If you have not created an Interface Builder palette for your
    custom view, there are two techniques you can use to create instances
    of your subclass within Interface Builder."

    Where do I learn how to do this?

    TIA,
    Rick
  • On Nov 22, 2007, at 11:25 AM, Rick Mann wrote:

    > I'm reading the NSView docs, and I got to the section on using IB.
    > It says, "If you have not created an Interface Builder palette for
    > your custom view, there are two techniques you can use to create
    > instances of your subclass within Interface Builder."

    Hey Rick -

    In Interface Builder you can specify that any instance can be of a
    different more derived type at runtime. To do this use the identity
    inspector (command + 6) and use the custom class combo box to type in
    a new class name. At runtime, an instance of that class will be
    instantiated in place of the selected object.

    So, if you subclassed NSView, drag an NSCustomView to your document.
    If you subclassed something more specific like an NSButton, drag an
    NSButton to your document. Once you've done that select the instance
    and use the identity inspector to change the class to your custom
    subclass. When you load your nib at runtime an instance of your custom
    class will be instantiated instead of the button.

    Jon Hess

    >
    >
    > Where do I learn how to do this?
    >
    > TIA,
    > Rick
  • On Nov 22, 2007, at 1:16 PM, Jonathan Hess wrote:

    > In Interface Builder you can specify that any instance can be of a
    > different more derived type at runtime. To do this use the identity
    > inspector (command + 6) and use the custom class combo box to type
    > in a new class name. At runtime, an instance of that class will be
    > instantiated in place of the selected object.
    >
    > So, if you subclassed NSView, drag an NSCustomView to your document.
    > If you subclassed something more specific like an NSButton, drag an
    > NSButton to your document. Once you've done that select the instance
    > and use the identity inspector to change the class to your custom
    > subclass. When you load your nib at runtime an instance of your
    > custom class will be instantiated instead of the button.

    Thanks.

    So, that's the second technique described by "View Programming Guide
    for Cocoa." It says:

    > The second technique is to specify a custom class is used when your
    > custom view subclass inherits
    > from a view that Interface Builder provides support for directly.
    > For example, you can create an
    > NSScrollView instance in Interface Builder and specify that a custom
    > subclass (MyScrollView) should
    > be used instead, again using the inspector. In this case, when the
    > nib file is loaded by the application,
    > the view instance has already been created and the MyScrollView
    > implementation of initWithFrame:
    > is never called. The MyScrollView instance receives an awakeFromNib
    > message and can configure
    > itself accordingly.

    The problem here is that, I don't see how my initWithFrame: could ever
    get called. IB needs to call that before archiving the view, and it
    doesn't have the ability to call it.

    Even if I had a custom palette for it, I don't see how it could call
    it, but the phrase "If you have not created an Interface Builder
    palette" implies that there is a way to create a palette.

    --
    Rick
  • On Nov 22, 2007, at 3:32 PM, Rick Mann wrote:

    >
    > On Nov 22, 2007, at 1:16 PM, Jonathan Hess wrote:
    >
    >> The second technique is to specify a custom class is used when your
    >> custom view subclass inherits
    >> from a view that Interface Builder provides support for directly.
    >> For example, you can create an
    >> NSScrollView instance in Interface Builder and specify that a
    >> custom subclass (MyScrollView) should
    >> be used instead, again using the inspector. In this case, when the
    >> nib file is loaded by the application,
    >> the view instance has already been created and the MyScrollView
    >> implementation of initWithFrame:
    >> is never called. The MyScrollView instance receives an awakeFromNib
    >> message and can configure
    >> itself accordingly.
    >
    > The problem here is that, I don't see how my initWithFrame: could
    > ever get called. IB needs to call that before archiving the view,
    > and it doesn't have the ability to call it.
    >
    > Even if I had a custom palette for it, I don't see how it could call
    > it, but the phrase "If you have not created an Interface Builder
    > palette" implies that there is a way to create a palette.

    I strongly suggest reading up on the docs for initWithFrame for when
    it will be called.  Also, check out my IB Plug-In sample code (I
    posted a link to that to this list and xcode-users).  Part of the
    sample sprinkles in some NSLog statements to make it easy to
    understand what methods IB calls at various points.

    The short of it...

    If you have a custom plug-in, IB will call initWithFrame: for those
    views that are contained within the plug-in library's nib.  When you
    drag an item off of the library, encodeWithCoder: is called against
    the instance.  Then, when it's dropped into say a window,
    initWithCoder: is called using the encoded data.  Finally, when the
    nib is saved, encodeWithCoder: is used to archive all your view's data.

    When you then run your app, all your custom views will be 'init'd'
    with initWithCoder:.  If you ever want to programatically create
    instances of your view, you'd then call either initWithFrame: or
    whatever designated initializer.

    So you can see that depending upon what you're doing, either
    initWithFrame: _or_ initWithCoder: will be used to initialize your
    instances.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • On Nov 22, 2007, at 1:32 PM, Rick Mann <rmann...> wrote:

    >
    > On Nov 22, 2007, at 1:16 PM, Jonathan Hess wrote:
    >
    >> In Interface Builder you can specify that any instance can be of a
    >> different more derived type at runtime. To do this use the identity
    >> inspector (command + 6) and use the custom class combo box to type
    >> in a new class name. At runtime, an instance of that class will be
    >> instantiated in place of the selected object.
    >>
    >> So, if you subclassed NSView, drag an NSCustomView to your
    >> document. If you subclassed something more specific like an
    >> NSButton, drag an NSButton to your document. Once you've done that
    >> select the instance and use the identity inspector to change the
    >> class to your custom subclass. When you load your nib at runtime an
    >> instance of your custom class will be instantiated instead of the
    >> button.
    >
    > Thanks.
    >
    > So, that's the second technique described by "View Programming Guide
    > for Cocoa." It says:
    >
    >> The second technique is to specify a custom class is used when your
    >> custom view subclass inherits
    >> from a view that Interface Builder provides support for directly.
    >> For example, you can create an
    >> NSScrollView instance in Interface Builder and specify that a
    >> custom subclass (MyScrollView) should
    >> be used instead, again using the inspector. In this case, when the
    >> nib file is loaded by the application,
    >> the view instance has already been created and the MyScrollView
    >> implementation of initWithFrame:
    >> is never called. The MyScrollView instance receives an awakeFromNib
    >> message and can configure
    >> itself accordingly.
    >
    > The problem here is that, I don't see how my initWithFrame: could
    > ever get called. IB needs to call that before archiving the view,
    > and it doesn't have the ability to call it.
    >
    > Even if I had a custom palette for it, I don't see how it could call
    > it, but the phrase "If you have not created an Interface Builder
    > palette" implies that there is a way to create a palette.
    >

    Hey Rick -

    Your view will get the initWithCoder: message when it has been
    integrated into a document by means of a plugin.  It will also get the
    initWithCoder: message if you use the custom class inspector method
    with anything other than NSCustomView. If you use NSCustomView you'll
    get initEithFrame:.

    From my iPhone -
    Jon Hess

    > --
    > Rick
    >
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today