Re: saving SplitView positions
Re: saving SplitView positions
- Subject: Re: saving SplitView positions
- From: Brian Webster <email@hidden>
- Date: Mon, 20 Jan 2003 17:04:07 -0600
On Monday, January 20, 2003, at 04:36 PM,
email@hidden wrote:
is there a fast and easy way to save splitView positions?
There's nothing built into the NSSplitView class to do this, but I've
done this before, and it's pretty easy to do using NSUserDefaults.
Here's a couple of code snippets where I save and restore my split view
position. This may be made more complex if you have more than two
views in your split view, but it should be pretty easy to extend this
idea if that's the case. In this code, I have two views side by side
in my split view, with the sourceTableView being the leftmost one.
This is even easier if your view isn't enclosed in a scroll view like
my table view is.
static NSString* MainWindowSplitViewPositionKey =
@"MainWindowSplitViewPosition";
//This method should be implemented by the application delegate, or
//you can also register a different object to receive this notification
- (void)applicationWillTerminate:(NSNotification*)notification
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
float splitViewPosition = [[sourceTableView enclosingScrollView]
frame].size.width;
[defaults setFloat:splitViewPosition
forKey:MainWindowSplitViewPositionKey];
}
//This method should be implemented by the object controlling the split
view
- (void)awakeFromNib
{
//Restore the splitter position
float splitViewPosition = [defaults
objectForKey:MainWindowSplitViewPositionKey];
if(splitViewPosition != nil && [splitViewPosition
isKindOfClass:[NSNumber class]])
{
NSScrollView* scrollView = [sourceTableView enclosingScrollView];
NSSize frameSize = [scrollView frame].size;
frameSize.width = [splitViewPosition floatValue];
[scrollView setFrameSize:frameSize];
}
}
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.