The scroll position is stored by NSScrollView
, which implements encodeRestorableStateWithCoder:
/restoreStateWithCoder:
since OS X Lion.
(Interface Builder automatically wraps a table view in a NSScrollView
→NSClipView
→NSTableView
hierarchy).
To get a scroll view that is scrolled to top after an app relaunch you have several options:
- Turn off view state restoration for the entire window in Interface Builder:
- Subclass
NSScrollView
and overrideencodeRestorableStateWithCoder:
with an empty implementation (Don't forget to set it as class for your your table view instance in IB): Programmatically scroll to top after app relaunch:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[self.scrollView contentView] scrollToPoint:NSMakePoint(0.0, 0.0)]; [self.scrollView reflectScrolledClipView:[self.scrollView contentView]]; }
Personally I'd go with method 3, because turning off state restoration for the whole window might break some behaviour that your users expect and method 2 is against Apple's recommendation on calling [super encodeRestorableStateWithCoder:]
when subclassing NSView
.