• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method


  • Subject: Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 02 Oct 2011 15:25:30 -0700

On Oct 2, 2011, at 13:14 , Gilles Celli wrote:

> Now I want to have a NSButtonCell for all the DataTypeNames (leaf node of the OvItem items class)…I've setup an NSOutlineView with 2 columns: first column named
> "buttonColumn" and a second one to display the Items…
>
> I've tried to generate the buttons with the NSOutlineView delegate method "outlineView:dataCellForTableColumn:item:" but it just show all the buttons
> for every row/items:
>
> Here's what I tried so far:
>
> - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
> {
>    //printf("delegate column identifier: %s\n", [[tableColumn identifier] cStringUsingEncoding:NSASCIIStringEncoding]);
>
>   NSCell* returnCell = [tableColumn dataCell];
>
>    NSTableColumn *checkboxColumn = [outlineViewChannels tableColumnWithIdentifier:@"buttonColumn"];
>
>    if ( ![(OvItem *)item isGroup]   )
>    {
>        if ( [[tableColumn identifier] isEqualToString:@"buttonColumn"]  )
>        {
>
>        NSButtonCell *cell = [[NSButtonCell alloc] init];
>
>        [cell setButtonType:NSSwitchButton];
>        [cell setTitle:@""];
>
>        [cell setEnabled:YES];
>        [cell setTransparent:NO];
>
>        [checkboxColumn setDataCell:cell];
>        [cell release];
>        }
>    }
>
> return returnCell;
>
> }

This is the correct basic approach, but there's no need to create a new cell every time this method is called. You can create it once, and return it whenever a cell of that kind is needed.

If you're seeing the same result in every row, regardless of type, then it's your 'if' test that's suspect first of all. Have you verified that the correct path is taken through this code for all three types of row?

Also, since (presumably) there are far more rows that *do* want to display the button cell than don't, you'd probably be better off reversing the logic. Set a button cell on the column in IB, and let [tableColumn dataCell] be the default. For the rows where you don't want the button, return a simple text cell instead. (You don't actually have to create this cell at all. You can use the one from the other column if you want. Any cell will do.)

In fact, there's an even better choice. If you read the documentation for 'outlineView:dataCellForTableColumn:item:', you'll see that it's *first* called with a nil table column. If you return a non-nil cell, then that cell is used to draw the whole row. That's probably your best choice for drawing the non-leaf rows, since it won't even leave room where the button would be. Looks better that way, and it allows you to add as many detail columns as you without without mucking up your higher-level rows.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
      • From: Gilles Celli <email@hidden>
References: 
 >NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method (From: Gilles Celli <email@hidden>)

  • Prev by Date: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
  • Next by Date: Mystery of the missing symbol
  • Previous by thread: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
  • Next by thread: Re: NSOutlineView - display NSButtonCell only for leaf node with outlineView:dataCellForTableColumn:item: method
  • Index(es):
    • Date
    • Thread