column of buttons in NSTableView

  • I just had a look at TableDemo at www.macdevcenter.com, which is very
    clear and easy to understand.

    I'd like to make some changes in it so that a column will contain
    switch buttons. It looks like this would be easy simply by creating
    as many instances of NSButtonCell as I need, setting their type to
    NSSwitchButton, putting them in an instance of NSArray that becomes
    part of my data source, etc. But this also seems wasteful of space if
    the column is very long, and I'm wondering whether there is a
    commonly-used, efficient way of accomplishing the job.  Feel free to
    tell me that I'm remiss for having overlooked something in the docs
    or in sample code that everyone should know about, but please point
    me to what I've missed.

    Thanks,
    Boyd
  • On Oct 30, 2006, at 4:02 PM, Boyd Collier wrote:
    > simply by creating as many instances of NSButtonCell as I need,
    > setting their type to NSSwitchButton, putting them in an instance
    > of NSArray that becomes part of my data source, etc.

      ... or ... ;-)

      In the Cocoa Data Views palette in Interface Builder, you can drag
    the cell type of your choice to the column of your choice and provide
    its object value in the data source methods ... or bind it ... or in
    code you can set the column's data cell manually ...

      Many ways to assign a data cell to a cat, as it were.

    --
    I.S.
  • First, thanks, I. Savant, for replying to my question.

    I didn't do a good job of asking the question, which really had to do
    with whether the table's data source used to establish a button in
    every row of a column that is to contain the buttons also had to hold
    an array of NSButtonCells, or whether a simpler and more efficient
    way of keeping track of the buttons' states could be used. After
    thinking it through, I realized that the answer is yes, and I
    implemented a way to do this simply by allocating an array of ints
    which are set either to 0 or 1, depending on whether the switch in
    the row of the table corresponding to the int in the array should be
    off or on. Then in objectValueForTableColumn: row: the value of the
    particular int that's keeping track of the state of the switch is
    determined and a single, autoreleased instance of NSButtonCell is
    allocated and used as the return value of this method. In the method
    setObjectValue: forTableColumn: row: I check the state of the switch
    in the column and set the int in the array of ints to the appropriate
    value.

    Seems to work very nicely, which I suppose most subscribers to this
    list already know (but we all gotta' start somewhere).

    Boyd

    On Oct 30, 2006, at 3:31 PM, I. Savant wrote:

    >
    > On Oct 30, 2006, at 4:02 PM, Boyd Collier wrote:
    > I just had a look at TableDemo at www.macdevcenter.com, which is
    > very clear and easy to understand.
    >
    > I'd like to make some changes in it so that a column will contain
    > switch buttons. It looks like this would be easy simply by creating
    > as many instances of NSButtonCell as I need, setting their type to
    > NSSwitchButton, putting them in an instance of NSArray that becomes
    > part of my data source, etc. But this also seems wasteful of space
    > if the column is very long, and I'm wondering whether there is a
    > commonly-used, efficient way of accomplishing the job.  Feel free
    > to tell me that I'm remiss for having overlooked something in the
    > docs or in sample code that everyone should know about, but please
    > point me to what I've missed.
    >
    > ... or ... ;-)
    >
    > In the Cocoa Data Views palette in Interface Builder, you can
    > drag the cell type of your choice to the column of your choice and
    > provide its object value in the data source methods ... or bind
    > it ... or in code you can set the column's data cell manually ...
    >
    > Many ways to assign a data cell to a cat, as it were.
    >
    > --
    > I.S.
previous month october 2006 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