PDA

View Full Version : setContentView




Darkroom
Nov 16, 2007, 11:12 AM
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:


#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



Darkroom
Nov 16, 2007, 12:47 PM
ok... i was able to get it to start working by adding this to the mainWindow.m:


- (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?

HiRez
Nov 16, 2007, 01:02 PM
ok... i was able to get it to start working by adding this to the mainWindow.m:


- (void)awakeFromNib {
[self setContentView:fullscreenView];
}


however, is there anyway to add the setContentView code to the init? or does it not matter?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:.