setContentView

Discussion in 'Mac Programming' started by Darkroom, Nov 16, 2007.

  1. Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    i have a custom view object called "windowColor" in my NIB... i'm trying to make the main window include the custom view for display when the window opens, but i can't get it to work. i've created an outlet in the mainWindow and connected it to the custom view object...the window starts up fine, but the custom view is not being displayed within the window... any help would be great:

    Code:
    #import <Cocoa/Cocoa.h>
    #import "windowColor.h"
    
    @interface mainWindow : NSWindow {
    	IBOutlet windowColor *fullscreenView;
    }
    
    @end
    
    -------
    
    #import "mainWindow.h"
    #import <Carbon/Carbon.h>
    
    @implementation mainWindow
    
    - (id) initWithContentRect: (NSRect) contentRect
                     styleMask: (unsigned int) aStyle
                       backing: (NSBackingStoreType) bufferingType
                         defer: (BOOL) flag
    	{
        if (self = [super initWithContentRect: contentRect
    							styleMask: NSBorderlessWindowMask
                                  backing: bufferingType
                                    defer: flag])
    	{
    	SetSystemUIMode(kUIModeAllHidden, 0);
    	[self setFrame:[[NSScreen mainScreen] visibleFrame] display:YES animate:NO];
    	[self setContentView:fullscreenView];
    	SetSystemUIMode(kUIModeAllSuppressed, 0);
    	}
        return self;
    }
    
    
    @end
    
     
  2. thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #2
    ok... i was able to get it to start working by adding this to the mainWindow.m:

    Code:
    - (void)awakeFromNib {
    		[self setContentView:fullscreenView];
    }
    
    however, is there anyway to add the setContentView code to the init? or does it not matter? i'm asking because i'm creating 2 windows (one for normal view, one for full screen view)... i'm just concerned that when i switch out of full screen to normal, and then back to full screen again the custom view "fullscreenView" will not register... any thoughts?
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    You have to do it in awakeFromNib: instead of init: because windows and views are UI Nib elements and won't be valid in init:. They are guaranteed to be valid in awakeFromNib:. Anytime you are modifying or hooking up UI elements, you probably want to do that in awakeFromNib:.
     

Share This Page