ronenmagid1
asked on
Retaining an NSWindow size and state - looking for an elegant way to do this
I have a controller class which spawns a window when a certain condition occurs. This window can be closed by the user, moved around or resized.
Ideally, when this condition occurs, I'd like the window to re-open in the same spot the user closed it last time.
Looking for an elegant way to do this. Pointers (or references) will be most welcome.
Ideally, when this condition occurs, I'd like the window to re-open in the same spot the user closed it last time.
Looking for an elegant way to do this. Pointers (or references) will be most welcome.
I'm not sure I understand. You want to know how to move? setFrame, I think. The parameter is NSRect.
ASKER
No, I can do that myself.
This is why I said "elegant". I thought there might be some Cocoa class that takes the snapshot of the windows location and/or if it's currently miniaturized and saves it into a pfile or something.
This is why I said "elegant". I thought there might be some Cocoa class that takes the snapshot of the windows location and/or if it's currently miniaturized and saves it into a pfile or something.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you need to store the rectangle somewhere and then read it and restore the view position?
Use NSUserDefaults. An example attached.
Use NSUserDefaults. An example attached.
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSDate date] forKey:@"Date and Time"];
[defaults synchronize];
NSDate *today = [defaults objectForKey:@"Date and Time"];
NSLog(@"Saved data: %@", today);
[pool drain];
return 0;
}