How about just a C array? If NBR_OF_ROWS is a constant, 

BOOL checks[NBR_OF_ROWS];

otherwise malloc it.

Although I'd be more likely to have an array of data objects with a BOOL and 
whatever goes in the text field, just to keep the two values together and allow 
for reordering, variable sized arrays, etc.

----- Original Message -----
From: "Gilles Celli" <gilles.ce...@ecgs.lu>
To: cocoa-dev@lists.apple.com
Sent: Wednesday, November 23, 2011 7:58:34 AM
Subject: Is there an easier way of changing NSButtonCell state in an 
NSOutlineView

Hello,

I've setup an NSOutlineView with 2 colums: the first one named "buttonColumns" 
with NSButtonCell (Switch ON / OFF)
and the second one with TextFieldCell…

While the state change works for NSButtonCell in the buttonColum I had to 
create an NSArray *checks to set it ON or OFF.
Is there an easier way to change the state of an NSButtonCell in an 
NSOutlineView without using an NSArray ?
The code I'm using seems a little bit overkill for me...there must be a simpler 
solution...

Here's what I've done so far and it works:

// init code

checks  = [[NSMutableArray alloc] init];
for ( int i=0; i <  NBR_OF_ROWS;  i++ )
        [checks addObject:[NSNumber numberWithInt:0]];

// NSOutlineView datasource methods

- (id)outlineView:(NSOutlineView *)outlineView 
objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
    id theValue;
  NSInteger selectedRowIndex = [outlineView selectedRow];
   if ( [[tableColumn identifier] isEqualToString:@"buttonColumn"] )
   {
      theValue = [checks objectAtIndex:selectedRowIndex]; 
    }
    return theValue;
}

- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object 
forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
    NSInteger selectedRowIndex = [outlineView selectedRow];

    if ( [[tableColumn identifier] isEqualToString:@"buttonColumn" ])
    {
       [checks replaceObjectAtIndex:selectedRowIndex withObject:object];
     }
}

Does someone have any clue ? Any help is greatly appreciated ?


Cheers,

Gilles

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/lrucker%40vmware.com

This email sent to lruc...@vmware.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to