I started objective C last week so I'm just beginning to understand how the MVC design pattern works. Basically I downloaded this open source web app wrapper in cocoa:
https://github.com/maccman/macgap
and I want to alter it so it remembers its window position when I re-open it.
I've already tried opening up the nib and assigning a value to Autosave however this did not work. After researching the issue I discovered this is because the window controller automatically turns cascading on, so within WindowController.m I put
[[self.window windowController] setShouldCascadeWindows:NO];
[self.window setFrameAutosaveName:[self.window representedFilename]];
I tried putting this in windowDidLoad and the init methods however this did not work either and the window still did not remember its position.
Finally within AppDelegate I noticed that this is the code that actually creates the controller:
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification {
NSRect frame = NSMakeRect(0, 0, 800, 600);
self.windowController = [[WindowController alloc] initWithURL: kStartPage
andFrame:frame];
[self.windowController showWindow: [NSApplication sharedApplication].delegate];
self.windowController.contentView.webView.alphaValue = 1.0;
self.windowController.contentView.alphaValue = 1.0;
[self.windowController showWindow:self];
}
As I said I started objective-c last week (for iOS development) and from that I know that the NSMakeRect is what's determining the window position. Now, I also know from Java that I could do something like write the coordinates to a binary file when it moves, then read that file when I start up the program and just feed these values into NSMakeRect, however I don't think this is the most elegant solution.