Fwd: Changing NSMatrix selection behavior without breaking bindings? [SOLVED]
Fwd: Changing NSMatrix selection behavior without breaking bindings? [SOLVED]
- Subject: Fwd: Changing NSMatrix selection behavior without breaking bindings? [SOLVED]
- From: "Lawrence Sanbourne" <email@hidden>
- Date: Tue, 18 Apr 2006 20:30:08 -0500
Solved!! I call this method at the end of my -mouseDown:
/*!
Update selectedIndex, selectedObject, selectedObjects, selectedTag,
selectedValue bindings.
*/
- (void)updateSelectionBindings {
int selectedCellPos = [self selectedRow] * [self numberOfColumns] +
[self selectedColumn];
NSCell *selectedCell = [self cellAtRow:[self selectedRow]
column:[self selectedColumn]];
[[observedObjects objectForKey:@"selectedIndex"] setValue:[NSNumber
numberWithInt:selectedCellPos] forKey:[keyPaths
objectForKey:@"selectedIndex"]];
[[observedObjects objectForKey:@"selectedObject"]
setValue:[selectedCell objectValue] forKey:[keyPaths
objectForKey:@"selectedObject"]];
[[observedObjects objectForKey:@"selectedTag"] setValue:[NSNumber
numberWithInt:[selectedCell tag]] forKey:[keyPaths
objectForKey:@"selectedTag"]];
[[observedObjects objectForKey:@"selectedValue"]
setValue:[selectedCell objectValue] forKey:[keyPaths
objectForKey:@"selectedValue"]];
if ([observedObjects objectForKey:@"selectedObjects"] != nil) {
NSMutableArray *selectedObjects = [[NSMutableArray alloc] init];
NSArray *selectedCells = [self selectedCells];
unsigned i, c = [selectedCells count];
for (i = 0; i < c; ++i)
[selectedObjects addObject:[[selectedCells objectAtIndex:i]
representedObject]];
[[observedObjects objectForKey:@"selectedObjects"]
setValue:selectedObjects forKey:[keyPaths
objectForKey:@"selectedObjects"]];
}
}
Works like a charm!
---------- Forwarded message ----------
From: Lawrence Sanbourne <email@hidden>
Date: Apr 18, 2006 1:35 PM
Subject: Changing NSMatrix selection behavior without breaking bindings?
To: email@hidden
Hello,
Here's a more succinct rephrasing of a question I asked recently. (It
didn't get any responses the first time around.)
In my app, I need custom selection behavior and drag-and-drop support
for cells in an NSMatrix. (The NSMatrix is bound to an
NSArrayController.) I did this by overriding -mouseDown and calling
selectCellAtRow:column: and setSelectionFrom:to:anchor:highlight:.
The problem is that this isn't updating my controller's
selectedObjects. Apple's "Troubleshooting Cocoa Bindings" document
says this is expected behavior because I should be updating the
controller, not the view. But in my case I need *custom* view
behavior, so I think I'm right in updating the view.
Does anyone know how to fix this? Please help!
Larry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden