Thanks for quick replies....things are a little more clear now, so I will stick 
with the NSArray version.

Just a question at Quincey: Maybe it's me, but I'm not sure how I could convert 
the 'item' parameter of both NSOutlineView datasource methods to a row number ? 
Where should I get the index value ?



On 23 nov. 2011, at 19:32, Quincey Morris wrote:

> On Nov 23, 2011, at 07:58 , Gilles Celli wrote:
> 
>> 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 ?
> 
> NSOutlineView and NSTableView are interface elements that are backed by a 
> data model. They do not store the data model, because they need to support 
> (virtually) very large numbers of rows, and keeping the data model (or a copy 
> of part of it) in the view would be too expensive of memory.
> 
> Therefore, you need to supply the data model, and then either provide a data 
> source or bindings to connect it to the view. You need either (a) this array 
> of BOOLs, or (b) a BOOL property of some objects in the rest of your data 
> model.
> 
>> The code I'm using seems a little bit overkill for me...there must be a 
>> simpler solution…
> 
> For a data source, this amount of code isn't overkill. Data source methods 
> often end up being wordy and ugly. You could eliminate the code altogether by 
> using bindings, but you'd have to use solution (b) above -- bindings need an 
> array property of some data model object, and your array doesn't qualify.
> 
> Also, I'm pretty sure your code is not doing what you thing it does:
> 
>> 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];
> 
> You're getting the 'checks' value for the *selected* row, which is not the 
> row whose object value is being asked for in this method. This means that 
> when the selection changes, the check boxes on *all* of the rows will change 
> (though you might not see that until redrawing of the entire view is forced).
> 
> Instead, you should convert the 'item' parameter to a row number.
> 
>>   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];
>>     }
>> }
> 

_______________________________________________

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