title: NSArrayController selection being reset
body: <p><strong>Short story:</strong></p>
  
  <p>The NSArrayController's selection is being reset whenever setContent is issued. I am wondering if there is a way to turn this off.</p>
  
  <p>Of course, this would be the only acceptable behaviour if I would let NSArrayController use its internal selectionIndexes, because then it wouldn't be able to keep track of both. However, the selectionIndexes are rewired as well, and this part goes off without a hitch. It still feels the need to reset the selection, though.</p>
  
  <p><strong>Update: Ugly hack solution</strong> </p>
  
  <p>I've moved this to an answer. I would be pleased to see another more insightful answer though.</p>
  
  <p><strong>Long story:</strong></p>
  
  <p>I have a Cocoa Document-based Application with an inspector panel that is shared between documents (modelled after the TextEdit source code that ships with xcode). Inside the Document class I have an NSMutableArray and an NSMutableIndexSet that are linked up with bindings to an NSArrayController. </p>
  
  <p>The inspector panel is in a separate nib file, and I have two identical NSArrayControllers, one from the main document window, and one from the inspector panel, so that both can interact with the document. This is why I do a manual binding to the selectionIndexes, so that I don't get two separate selections with the two separate NSArrayControllers.</p>
  
  <p>The inspector panel keeps track of which document is being inspected by a:</p>
  
  <pre><code>Document *inspectedDocument;
  </code></pre>
  
  <p>which is updated whenever the document is switched, or no document has focus at all. An NSObjectController is linked up to <code>inspectedDocument</code>, and the NSArrayController I mentioned before is linked up to that controller.</p>
  
  <p>Now, my problem is that when the inspector panel is in place, and the <code>inspectedDocument</code> is changed, the selection indexes are reset. The problem goes away if I don't use the inspector panel, so I assume it is its NSArrayController that is issuing this reset. I don't have any controls that bind to the selection and could change it (such as a table view).</p>
  
  <p>In the inspector panel's NSArrayController, if I have "Avoid Empty Selection" ticked, the selection resets to the first object, otherwise it resets to no selection, so it is definitely a legitimate resetting of the selection. Actually, I don't even want the inspector panel to ever be able to change the selection, so ideally I would like to establish a read-only binding for that NSArrayController's selection indexes.</p>