Link to home
Start Free TrialLog in
Avatar of ronenmagid1
ronenmagid1Flag for United States of America

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.
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

I'm not sure I understand. You want to know how to move? setFrame, I think. The parameter is NSRect.

Avatar of ronenmagid1

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.
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you need to store the rectangle somewhere and then read it and restore the view position?
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;
}

Open in new window