Re: Subclassed control in IB uses original cell class

  • > The problem is that the control ends up with a NSSliderCell and not a
    > SMDoubleSliderCell - guess +cellClass does not get invoked for
    > archived objects.

    Yeah - here's how to think of it.

    +cellClass is used when a control needs to instantiate a cell for
    itself and it doesn't already have one.

    With a nib, both the control and the cell are instantiated in
    interface builder, then archived.  -[NSControl initWithCoder:] has
    code that looks more or less like this:

    _cell = [[coder decodeObjectForKey:@"NSCell"] retain];

    So +cellClass might be called inside of Interface Builder, but it will
    not be at runtime in your app.  Unless you write an IB plugin, your
    implementation of +cellClass will not be present in IB.

    There's a solution, though: In IB3, select the cell in IB and set its
    class to your custom subclass, the same as you would do for any other
    object in a nib.  Exposing cells as first class objects is a major new
    IB feature.

    -Ken

    On 11/28/07, David Hoerl <dhoerl...> wrote:
    > I found a neat double knobbed slider on the web:
    > http://developer.snowmintcs.com/controls/smdoubleslider/
    >
    > There is only a IB2 palette, so I figured I'd just add a NSSlider
    > object to my NIB, change its class to SMDoubleClass, then do anything
    > further in awakeFromNib.
    >
    > The problem is that the control ends up with a NSSliderCell and not a
    > SMDoubleSliderCell - guess +cellClass does not get invoked for
    > archived objects.
    >
    > At first, I could not subclass the cell as a nib2.x file does not
    > support it. However, the IB3 docs say I can use the nib3.x file on
    > Tiger (for building only, not editing). So, I changed formats,
    > changed the cell class, and now all is working as expected.
    >
    > I was wondering though - suppose I had to stay with IB2 - how would I
    > get the correct class of cell?
    >
    > David
    >
previous month december 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
31            
Go to today