I have tried many possibilities I found on this site and read some explanations from apple developer page, but seems like i couldn't resolve my problem about loading NSViewController with/form NIB.
Files on Xcode Project look a bit like this :
- SecondViewController.h
- SecondViewController.m
- SecondViewController.xib
- AppDelegate.h
- AppDelegate.m
- MainMenu.xib
The main problem is how could i create the SecondViewController programatically with the initial nib on SecondViewController.xib
- Custom class of FileOwner on MainMenu.xib is NSApplication
- Custom class of FileOwner on SecondViewController.xib is SecondViewController
- There are some panels and window in MainMenu.xb (about window and preference panel)
- This application has no main window (using notification icon on status bar)
SecondViewController.h
@interface SecondViewController : NSViewController {
BOOL fullScreenMode;
NSImageView *fullScreenbg;
NSImageView *imageView1;
NSImageView *imageView2;
NSPanel *imageWindow;
}
@property (assign) IBOutlet NSImageView *fullScreenbg;
@property (assign) IBOutlet NSImageView *imageView1;
@property (assign) IBOutlet NSImageView *imageView2;
@property (assign) IBOutlet NSPanel *imageWindow;
SecondViewController.m
@implementation SecondViewController {
NSImageView *nv1;
NSImageView *nv2;
NSSize curImgSize;
}
@synthesize fullScreenbg;
@synthesize imageView1;
@synthesize imageView2;
@synthesize imageWindow;
......
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
fullScreenMode = YES;
}
return self;
}
AppDelegate.h
@interface AppDelegate : NSObject <NSApplicationDelegate,NSWindowDelegate> {
NSPanel *aboutWindow;
IBOutlet NSMenu *myStatusMenu;
IBOutlet NSMenuItem *toggleFullScreen;
}
AppDelegate.m
@implementation AppDelegate {
SecondViewController *controller;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
controller = [[SecondViewController alloc]
initWithNibName:@"SecondViewController"
bundle:nil];
//Not work (fullscreenbg, imageView1, imageView2,imageWindow = nil)
//controller = [[SecondViewController alloc] init]; ?? <-- didn't work either
}
Even if using initWithNibName or just init, all the IBOutlet properties seems to be nil on debug.
i've tried other solustions like "NSBundle loadNibNamed" or using loadView but it didn't work (warning message : "NSObject my not respond to loadView").
The main purpose of the secondViewController is to display notification message including graphics and web element.
I hope someone could give me a best suggestion. Thanks.