Search code examples
objective-ccocoanstableviewnsarraycontroller

How to send message after NSArrayController did automatically rearrange it's objects?


I did enable automaticallyRearrangesObjects in my NSArrayController.

This works fine, but i would like to send -scrollRowToVisible to the related NSTableView each time the NSArrayController rearranged, so that the currently selected row stays always visible.

Where could i put this, so that it get's sent at each rearrangement?


Solution

  • You can use KVO to observe the array controller's arrangedObjects property. When that changes, you can scroll.

    (For what it's worth, this may annoy your users if they have deliberately scrolled to view another part of the table.)