Center Window If There Is No setFrameAutosaveName?

Discussion in 'Mac Programming' started by Darkroom, Jul 12, 2008.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    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");
    		}
    	}
    
     
  2. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #2
    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...
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    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"];
    	}
    
     

Share This Page