Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
in my mainWindow.m file, i'm trying to center the mainWindow if it's the first time the app is launched. if it's not the first time, than setFrameAutosaveName... shouldn't this code work??:

Code:
- (void)awakeFromNib
	{
	if (![[NSUserDefaults standardUserDefaults] objectForKey: @"MAINWINDOWPositionHeightWidth"])
		{
		[self center];
		NSLog (@"First App Launch, Window Is Centered");
		}
		else
		{
		[self setFrameAutosaveName:@"MAINWINDOWPositionHeightWidth"];
                NSLog (@"Window Is In The Same State The User Left It");
		}
	}
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
whatever... i'll just center it manually in IB... but i think it's kinda ghetto that Apple doesn't include a "Center Window On Main Screen" option under Content Size & Position, especially since they do have a "Use Current" option... seems kinda dumb to me...
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
humm... so i just realized that my app's main window is way off on smaller screens if i center it manually... does anyone have an answer to my problem? seems like it shouldn't be too complex... unless i'm doing something ultra dumb, in which case i would appreciate if you'd please tell me.

so what's wrong with this code?
Code:
- (void)awakeFromNib
	{
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	if (![standardUserDefaults objectForKey:@"MAINWINDOWPositionHeightWidth"])
		{
		[self center];
		}
		else
		{
		[self setFrameAutosaveName:@"MAINWINDOWPositionHeightWidth"];
		}
	}

[EDIT] sorry, i have it working now... but i swear i did this already at first and it didn't work... oh well... this is what works:

Code:
- (void)awakeFromNib
	{
	[self center];
	[self setFrameAutosaveName:@"MAINWINDOWPositionHeightWidth"];
	}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.