In my app I have a NSTableView
in NSViewController
with a NSArrayController
provide the content.
It works great, however, when I scroll to some position of tableview, quit app and re-launch it, It will restore the last scroll position. I don't like this behavior, I want it to keep at the top.
I tried to setAutosaveTableColumns
to NO on NSTableView, it seems not the option I need. It still works the old way.
Does is any option to turn this off?
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:
NSScrollView
and override encodeRestorableStateWithCoder:
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.