NSPopUpButtonCell in custom NSTableColumn in NSTableView - not changing value

  • I've created a custom subclass of NSTableColumn to allow me to have a
    different popup menu for each cell.  I override dataCellByRow and add a
    setDataCellByRow method.  I can populate the cell fine, but whenever I try
    to change the value it immediately flicks back to the original value.  I
    assume I've missed something in the event handling / action chain, but I'm
    not sure what.

    What do I need to do to allow an NSPopupCell created via [NSPopupCell
    initWithText: @"blah" pullDown: NO] to keep its value?  By the time I call

    - (id) tableView: (NSTableView *) aTableView
    objectValueForTableColumn: (NSTableColumn *) aTableColumn
    row: (int) rowIndex

    the value of [selected cell] seems to have reverted to its orginal value,
    not the one I changed it to.

    For reference: enabled is true, and

    - (void) tableView: (NSTableView *) aTableView
    setObjectValue: (id) anObject
    ForTableColumn: (NSTableColumn *) aTableColumn
    row: (int) rowIndex

    is never called.

    Related question: NSTableColumn conforms to NSCoding.  What - if anything -
    do I need to do to ensure that my subclass plays nice with NSCoder.
    Currently, I override initWithCoder to initialise my data structures but do
    not try to encode any of them.

    --
    Andrew White

    --------------------------------------------------------------------------
    This email and any attachments are confidential. They may contain legally
    privileged information or copyright material. You should not read, copy,
    use or disclose them without authorisation. If you are not an intended
    recipient, please contact us at once by return email and then delete both
    messages. We do not accept liability in connection with computer virus,
    data corruption, delay, interruption, unauthorised access or unauthorised
    amendment. This notice should not be removed.
  • On Mar 11, 2005, at 3:17 PM, Andrew White wrote:

    >
    > I've created a custom subclass of NSTableColumn to allow me to have a
    > different popup menu for each cell.  I override dataCellByRow and add
    > a setDataCellByRow method.  I can populate the cell fine, but whenever
    > I try to change the value it immediately flicks back to the original
    > value.  I assume I've missed something in the event handling / action
    > chain, but I'm not sure what.
    >
    > What do I need to do to allow an NSPopupCell created via [NSPopupCell
    > initWithText: @"blah" pullDown: NO] to keep its value?  By the time I
    > call
    >
    > - (id) tableView: (NSTableView *) aTableView
    > objectValueForTableColumn: (NSTableColumn *) aTableColumn
    > row: (int) rowIndex
    >
    > the value of [selected cell] seems to have reverted to its orginal
    > value, not the one I changed it to.
    >
    > For reference: enabled is true, and
    >
    > - (void) tableView: (NSTableView *) aTableView
    > setObjectValue: (id) anObject
    > ForTableColumn: (NSTableColumn *) aTableColumn
    > row: (int) rowIndex
    >
    > is never called.

    The answer is in the line above.
  • stephane sudre wrote:
    >
    > On Mar 11, 2005, at 3:17 PM, Andrew White wrote:

    >> For reference: enabled is true, and
    >>
    >> - (void) tableView: (NSTableView *) aTableView
    >> setObjectValue: (id) anObject
    >> ForTableColumn: (NSTableColumn *) aTableColumn
    >> row: (int) rowIndex
    >>
    >> is never called.
    >
    >
    > The answer is in the line above.

    Leaving aside that your comment is only restating the symptoms, not an
    answer, I'm not convinced.  I installed an action in the menu, and when
    that action is resolved the selected value is still the original (not the
    changed value).  The action code occurs before the table view is updated.

    ie:

    - Tweak cell from index 2 to index 3
    - Action triggers.  Value of [cell indexOfSelectedItem] is 2.
    - tableView:objectValueForTableColumn:row triggers.

    Something internal to the cell's own processing seems to be reseting its
    value before we even get to action resolution.

    --
    Andrew White

    --------------------------------------------------------------------------
    This email and any attachments are confidential. They may contain legally
    privileged information or copyright material. You should not read, copy,
    use or disclose them without authorisation. If you are not an intended
    recipient, please contact us at once by return email and then delete both
    messages. We do not accept liability in connection with computer virus,
    data corruption, delay, interruption, unauthorised access or unauthorised
    amendment. This notice should not be removed.
  • Andrew White wrote:
    >
    > I've created a custom subclass of NSTableColumn to allow me to have a
    > different popup menu for each cell.  I override dataCellByRow and add a
    > setDataCellByRow method.  I can populate the cell fine, but whenever I
    > try to change the value it immediately flicks back to the original
    > value.  I assume I've missed something in the event handling / action
    > chain, but I'm not sure what.

    Partial solution:

    I add an action / target pair to each menu _item_, then in the handler for
    that action check which menu item called the handler and set the selected
    item to that value.  I still don't see a call to
    tableView:setObjectValue:forTableColumn:row.

    What I don't understand is why I have to add all this infrastructure
    manually to NSPopUpButtonCell, while an NSPopUpButton created in IB 'just
    works'.

    --
    Andrew White

    --------------------------------------------------------------------------
    This email and any attachments are confidential. They may contain legally
    privileged information or copyright material. You should not read, copy,
    use or disclose them without authorisation. If you are not an intended
    recipient, please contact us at once by return email and then delete both
    messages. We do not accept liability in connection with computer virus,
    data corruption, delay, interruption, unauthorised access or unauthorised
    amendment. This notice should not be removed.
  • Op 11-mrt-05 om 15:17 heeft Andrew White het volgende geschreven:

    >
    > - (void) tableView: (NSTableView *) aTableView
    > setObjectValue: (id) anObject
    > ForTableColumn: (NSTableColumn *) aTableColumn
    > row: (int) rowIndex
    >
    >

    Is it a mail typo, or does your actual code contain the capital 'F' in
    ForTableColumn?

    Regards,

    Steven Kramer

    --
    <steven...>
    http://sprintteam.com/
  • Steven Kramer wrote:
    >
    > Op 11-mrt-05 om 15:17 heeft Andrew White het volgende geschreven:
    >
    >>
    >> - (void) tableView: (NSTableView *) aTableView
    >> setObjectValue: (id) anObject
    >> ForTableColumn: (NSTableColumn *) aTableColumn
    >> row: (int) rowIndex
    >>
    >>
    >
    > Is it a mail typo, or does your actual code contain the capital 'F' in
    > ForTableColumn?

    Good catch.  I'm surprised the compiler didn't complain about it (no method
    definition ...), but it didn't.  Changing the case does indeed cause this
    code to be called (mutters).

    Thanks

    --
    Andrew White

    --------------------------------------------------------------------------
    This email and any attachments are confidential. They may contain legally
    privileged information or copyright material. You should not read, copy,
    use or disclose them without authorisation. If you are not an intended
    recipient, please contact us at once by return email and then delete both
    messages. We do not accept liability in connection with computer virus,
    data corruption, delay, interruption, unauthorised access or unauthorised
    amendment. This notice should not be removed.
  • The past two days I've been trying to manually fill an NSTableView with
    columns containing NSImageCells.
    Needless to say I haven't succeeded ;-)

    What I do so far is that I create an empty NSTableView in IB and then
    try to fill it in my Controller by allocating and initing NSCells and
    adding them to allocated and inited NSTableColumns. I fear this is not
    entirely right.

    Now my questions:
    1) Do I have to retain the NSTableColumns that I create?
    2) Do I have to retain the NSCells that I create and add to the
    NSTableColumns (above)?

    Could somebody give me a hint to a useful document concerning the
    subject of creating an NSTableView from scratch using NOT text-cells but
    image-cells. I'm boggled.

    Any help would be greatly appreciated (I will mentally build a shrine
    for you).

    Regards,

    Ole.
  • Ole:

      I'm afraid you're not quite approaching this correctly. You should
    read this:

    http://developer.apple.com/documentation/Cocoa/Conceptual/TableView/
    index.html

    --
    I.S.

    On Oct 19, 2006, at 10:58 AM, Ole Voss wrote:

    >
    > The past two days I've been trying to manually fill an NSTableView
    > with columns containing NSImageCells.
    > Needless to say I haven't succeeded ;-)
    >
    > What I do so far is that I create an empty NSTableView in IB and
    > then try to fill it in my Controller by allocating and initing
    > NSCells and adding them to allocated and inited NSTableColumns. I
    > fear this is not entirely right.
    >
    > Now my questions:
    > 1) Do I have to retain the NSTableColumns that I create?
    > 2) Do I have to retain the NSCells that I create and add to the
    > NSTableColumns (above)?
    >
    > Could somebody give me a hint to a useful document concerning the
    > subject of creating an NSTableView from scratch using NOT text-
    > cells but image-cells. I'm boggled.
    >
    >
    > Any help would be greatly appreciated (I will mentally build a
    > shrine for you).
    >
    >
    > Regards,
    >
    > Ole.
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/idiotsavant2005%
    > 40gmail.com
    >
    > This email sent to <idiotsavant2005...>
  • On Thu, 19 Oct 2006 16:58:04 +0200, Ole Voss <usenet...> said:
    >
    > The past two days I've been trying to manually fill an NSTableView with
    > columns containing NSImageCells.
    > Needless to say I haven't succeeded ;-)
    >
    > What I do so far is that I create an empty NSTableView in IB and then
    > try to fill it in my Controller by allocating and initing NSCells and
    > adding them to allocated and inited NSTableColumns.

    Wait - that doesn't make sense. If you're creating the NSTableView in IB,
    can you explain why you don't also set the cell types of the columns as
    NSImageCell right there? That's what the little picture of a mountain in the
    Cocoa-Data widget pane is for. Just drag it onto a column in the table.
    Poof, it's an image-cell column.

    However, if you really want to create image-cell columns from scratch,
    here's the code:

    NSTableColumn* tc = [[[NSTableColumn alloc]
    initWithIdentifier:@"fileIconColumn"] autorelease];
    [tc setDataCell: [[[NSImageCell alloc] initImageCell: nil] autorelease]];
    [theTable addTableColumn:tc];

    m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • > On Thu, 19 Oct 2006 16:58:04 +0200, Ole Voss <usenet...> said:
    >
    >> The past two days I've been trying to manually fill an NSTableView with
    >> columns containing NSImageCells.
    >> Needless to say I haven't succeeded ;-)
    >>
    >> What I do so far is that I create an empty NSTableView in IB and then
    >> try to fill it in my Controller by allocating and initing NSCells and
    >> adding them to allocated and inited NSTableColumns.
    >>
    >
    > Wait - that doesn't make sense. If you're creating the NSTableView in IB,
    > can you explain why you don't also set the cell types of the columns as
    > NSImageCell right there? That's what the little picture of a mountain in the
    > Cocoa-Data widget pane is for. Just drag it onto a column in the table.
    > Poof, it's an image-cell column.
    >
    > However, if you really want to create image-cell columns from scratch,
    > here's the code:
    >
    > NSTableColumn* tc = [[[NSTableColumn alloc]
    > initWithIdentifier:@"fileIconColumn"] autorelease];
    > [tc setDataCell: [[[NSImageCell alloc] initImageCell: nil] autorelease]];
    > [theTable addTableColumn:tc];
    >
    > m.
    >
    >

    I'm sorry everybody. I was jumping ahead because I've been busy with
    this and my head just got cluttered.

    I know about the IB and using NSImageCells from the palette - that I've
    done lots of times and it works fine for tables where I know before how
    many columns I want displayed. Unfortunately this time I have to react
    dynamically and add and remove columns as I import data. So I'm stuck
    with having to manage this from scratch... Sorry for being so confused.

    @Matt: Thanks for the example. That is actually what I've been doing,
    but I didn't autorelease the Cells/Columns. Instead I retained them
    myself because I wasn't sure if a TableView keeps tabs on them itself.
    Somehow this is not working though... I'm going to check on my code
    again - and will add the autorelease instead of hogging memory ;-)

    Regards,

    Ole.
previous month march 2005 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