ButtonCell with Text in OutlineView

  • I'm trying to have a hierarchical set of choices with a checkbox next to
    each one. How can I best set this up?
    My current thinking was to try and create a NSButtonCell subclass which
    would act like a NSTextCell in that setting its value would set its title,
    but I'd parse the string which is encoded with a flag to indicate if the
    button is selected or not.

    I have NSTreeController bound to my model and the column in NSOutlineView
    bound to the appropriate key path in NSTreeController.

    I do not understand how the column in the NSOutlineView knows how to set the
    property to the cell. How are the cell and column related? How do they
    interact?

    What method do I need to implement in my cell to intercept the value being
    set so that I can in turn set the title and button state?

    Is this the best approach? Is there some other preferred approach to this
    common problem?

    Thanks
  • On Thu, May 15, 2008 at 1:39 PM, David <enki1711...> wrote:
    > I do not understand how the column in the NSOutlineView knows how to set the
    > property to the cell. How are the cell and column related? How do they
    > interact?

    You bind the value of the column to a property, and then the column
    loops N times, where N is the number of rows, setting the cell's value
    and then drawing the cell in each row.  It's non-obvious until you
    really understand how the view/cell dichotomy works.

    > Is this the best approach? Is there some other preferred approach to this
    > common problem?

    I'm hesitant to suggest this because it seems like bad form (reminds
    me of the magic \t character in Windows menus that separates the menu
    item name from its accelerator key) but you could probably use a
    custom cell and override its -setObjectValue: method to parse your
    string and then call -setTitle: as appropriate.

    --Kyle Sluder
  • Is there a document which describes how columns interact with enclosed cells
    when dealing with bindings?

    There's a message flow going on that I'm not aware of. setObjectValue is
    passed different things for the same binding depending on if my class
    subclasses NSTextFieldCell or NSButtonCell. I don't see a way to fake it out
    without seeing more of the message flow. Too bad the source code isn't
    available. In the Java world, if worse comes to worse you can read the
    source to understand how framework classes interact.

    I've also read about a delegate method on
    NSOutlineView, outlineView:willDisplayCell:forTableColumn:item:
    Is this a more appropriate way to solve the problem? Should I be able to
    modify the title of a button cell through this delegate method?

    On Fri, May 16, 2008 at 1:58 AM, Kyle Sluder <
    kyle.sluder+<cocoa-dev...> <kyle.sluder%<2Bcocoa-dev...>> wrote:

    > On Thu, May 15, 2008 at 1:39 PM, David <enki1711...> wrote:
    >> I do not understand how the column in the NSOutlineView knows how to set
    > the
    >> property to the cell. How are the cell and column related? How do they
    >> interact?
    >
    > You bind the value of the column to a property, and then the column
    > loops N times, where N is the number of rows, setting the cell's value
    > and then drawing the cell in each row.  It's non-obvious until you
    > really understand how the view/cell dichotomy works.
    >
    >> Is this the best approach? Is there some other preferred approach to this
    >> common problem?
    >
    > I'm hesitant to suggest this because it seems like bad form (reminds
    > me of the magic \t character in Windows menus that separates the menu
    > item name from its accelerator key) but you could probably use a
    > custom cell and override its -setObjectValue: method to parse your
    > string and then call -setTitle: as appropriate.
    >
    > --Kyle Sluder
    >
previous month may 2008 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