Take the 2-minute tour ×

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];
    [[self mutableArrayValueForKey:@"dataArray"] addObject:item];


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

share|improve this question
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? –  noa Mar 19 '12 at 1:36
@noa yes, that's correct... any clue? –  glasz Mar 20 '12 at 22:45

1 Answer 1

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.

share|improve this answer
yes. i know. but according to this and other resources i've read the other approach should be working as well since it is kvo-compliant. i'd really like to know why there's this visual oddness... –  glasz Mar 22 '12 at 11:39
Thanks for posting those links – helps me understand what you're attempting. Your approach is working, in that the items are showing up. It's selectsInsertedObjects which isn't behaving correctly. What results do you get when the items you insert are unique (e.g. more than one second apart)? –  noa Mar 22 '12 at 15:30

Your Answer


