2
votes

now, i've been reading just about everything about NSArrayController.
i have properly setup my xib, the NSArrayController, NSTableView and the bindings -- everything's working except for one odd behavior of my NSTableView.

First some code to picture the scene:

@implementation MyAppDelegate

@synthesize arrayController, dataArray;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.dataArray = [NSMutableArray array];
}

- (IBAction)myControllerAddAction:(id)sender {
    NSString *val = [[NSDate date] description];
    NSMutableDictionary *item = [NSMutableDictionary dictionaryWithObjectsAndKeys:val, @"date", nil];
    [serversController addObject:item];
}

- (IBAction)myArrayAddAction:(id)sender {
    NSString *val = [[NSDate date] description];
    NSMutableDictionary *item = [NSMutableDictionary dictionaryWithObjectsAndKeys:val, @"date", nil];
    [[self mutableArrayValueForKey:@"dataArray"] addObject:item];
}

@end

using -mutableArrayValueForKey:@"myNSArrayControllerStore" and adding objects via the returned NSMutableArray proxy's -addObject:myDictionary the array controller instructs the table view to draw the new content but it'll select all rows with the same values in their NSCells:

enter image description here

using the array controller's -addObject:myDictionary it'll draw the new row and select the newly added one:

enter image description here

(on both screens i've been continuously clicking multiple times per second)

Why is that?
Do i need to handle proper row selection on my own when using [NSMutableArray -addObject:]?
Or is this a bug?

Mac OS 10.7.3
Xcode 4.3
Base SDK 10.7
Deployment target 10.6

1
I don't understand these screenshots. In the first screenshot, it's selecting all the :17 lines, the ones which match the first item added. In the second, there's only a single item with the given value. I take it in the first case, each click expands the original selection until the time changes to the next second, and in the second case, the selection moves after each click?paulmelnikow
@noa yes, that's correct... any clue?glasz

1 Answers

0
votes

Using an array controller's -addObject: method is the right way to handle insertion. It ensures the controller sends the right messages to objects which are bound to it.

It sounds like the array controller approach is working correctly.

It would be useful to be able to bind array controllers to mutable arrays, and for them correctly to monitor insertions to the bound arrays, but I don't think they are designed to work in this manner.