NSTableView/datasource question
NSTableView/datasource question
- Subject: NSTableView/datasource question
- From: Charles Lunetta <email@hidden>
- Date: Mon, 2 Aug 2004 17:52:27 -0700
Hello,
I have an NSTableView that uses an NSMutableDictionary (of
NSString/NSArray keys/values) as the datasource that is driven from the
selection in an NSComboBox. If a change is made to the NSTableView
when the "Blank" item is selected in the NSComboBox the following
tatkes place:
* an "Untitled" item is added to the NSComboBox
* an "Untitled" key/copy of the "Blank" value is added to the
NSMutableDictionary
* the "Untitled" NSMutableDictionary value is changed to reflect the
new NSTableView value
The problem is that BOTH the "Blank" and "Untitled" NSMutableDictionary
values reflect the new NSTableView value, though I only change the
"Untitled" key's value. Please find relevant code below. HELP!
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)aRowIndex
{
NSMutableArray *anArray, *rowArray, *colArray, *theArray; //
Arrays to hold schedule parts
if ([[theNSComboBox stringValue] compare: @"Blank"] == NSOrderedSame)
{ // If you are changing the Blank schedule
anArray = [[theNSComboBox objectValues] mutableCopy]; //
Get the NSComboBox list
[anArray addObject: @"Untitled"]; // Add the Untitled
schedule
[anArray sortedArrayUsingSelector: @selector(compare:)]; //
Sort the list
[theNSComboBox removeAllItems]; // Clear the
NSComboBox
[theNSComboBox addItemsWithObjectValues: anArray]; //
Repopulate the NSComboBox
theArray = [theNSMutableDictionary objectForKey:
@"Blank"]; // Copy the Blank schedule
[theNSMutableDictionary setObject: theArray forKey:
@"Untitled"]; // Add the Untitled schedule to the dictionary
[theNSComboBox selectItemWithObjectValue: @"Untitled"]; //
Select the Untitled schedule
}
theArray = [theNSMutableDictionary objectForKey: [theNSComboBox
stringValue] ]; // Get the schedule array
colArray = [theArray objectAtIndex: 3 + [[aTableColumn identifier]
intValue] / 2 ]; // Get the schedule column array
rowArray = [colArray objectAtIndex: aRowIndex]; // Get
the label and min array
// At this point the debugger shows the dictionary with Blank and
Untitled, the latter with the same value as Blank
// As soon as the next line executes the debugger shows that BOTH the
Blank and the Untitled dictionary values change! WHY BOTH??
[rowArray replaceObjectAtIndex: [[aTableColumn identifier] intValue] %
2 withObject: anObject]; // Update the array item
[colArray replaceObjectAtIndex: aRowIndex withObject:
rowArray]; // Replace the column array
[theArray replaceObjectAtIndex: 3 + [[aTableColumn identifier]
intValue] / 2 withObject: colArray]; // Replace the schedule array
[theNSMutableDictionary setObject: theArray forKey: [theNSComboBox
stringValue] ]; // Update the dictionary
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.