Restore selection to NSTableView (NSWindowRestoration)

I am working on window repair in a non-document based Cocoa application. The application has a Mail.app-like interface. Each window represents an account; the sidebar in this window displays conversations in this account, and the main area displays messages in the selected conversation.

Each of these lists is based on browsing NSTableView. The conversation list is tied to NSArrayControllerwhose contentSettied to the property of the window controller account; the list of messages is tied to the second NSArrayController, whose is contentSettied to the first segment NSArrayController.

I restored my job of restoring a window to such an extent that it reopens all the windows and reassociates them with the account objects, but I don’t know how to restore the selection of table types. This does not happen automatically - when the window is restored, the object is selected, but not the one that was previously selected. What's going on here? What would be the easiest way to save and restore choices?

+5
source share
1 answer

As you understand, it NSTableViewdoes not save the selection automatically.

- NSTableView selectionIndexes Array Controller selectionIndexes / NSUserDefaults. selectionIndexes Shared User Defaults Controller ( values Model Key Path ). NSIndexSet / , NSKeyedUnarchiveFromData. .


, , ( , , ), .

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:[NSKeyedArchiver archivedDataWithRootObject:self.arrayController.selectionIndexes] valueForKey:vvLastSavedSelectionIndex];

:

NSIndexSet *selectionIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] valueForKey:vvLastSavedSelectionIndex]];
[self.arrayController setSelectionIndexes:selectionIndexes];
+5

All Articles