4
votes

My setup:

I'm making a tab-based application using an NSTableView to display tabs and allow users to select tabs.

I have an NSTableView bound to an NSArrayController (tableView.content is bound to arrayController.arrangedObjects, tableView.selectionIndexes is bound to arrayController.selectionIndexes).

tableView bindings

My arrayController content is bound to an NSMutableArray in my ViewController.

arrayController bindings

My arrayController is NOT set to select inserted objects (see screenshot)

arrayController properties

My problem:

Whenever I call [myArrayController addObject:], the selectedIndex changes back to 0 (even though I have "Preserve Selection" checked). I don't want this behavior. I want the selection to remain on the same tab after adding or removing objects.

Has anyone run into this situation before?

1
I notice that you're binding the arrayController's Selection Indexes property to a property on the File's Owner called selectedIndex. The Selection Indexes property of NSArrayController is an NSIndexSet and not an NSUInteger. I can easily imagine how a mismatch like that could manifest in the problem you're seeing.ipmcc
Sadly, the selectedIndex property is actually an NSIndexSet in my File's Owner, though I agree, I'll probably rename it to avoid confusion.Chris R

1 Answers

0
votes

Deselecting "Avoid Empty Selection" fixed a similar issue for me (my first inserted object was automatically selected). Apple says that the NSArrayController will maintain a selection unless there are no objects in the array, which seems like it wouldn't affect an existing selection but it could be worth a shot.