I am working on a visual editor application for OSx
Currently, the application opens my MainMenu.xib.
I would like to present user when opening the application with a Welcome window, listing the previous opened projects, and a button to create a new project (actually linking to my App Delegate menuNewProject method)
What is the best approach to open this "Welcome" xib instead of MainMenu xib ?
Make my current app delegate open the Welcome xib like this ?
Welcome *welcome = [[Welcome alloc] initWithWindowNibName:@"Welcome"];
and then hide my MainMenu window ?
Or make the starting point of my application Welcome xib and not MainMenu, and open my visual editor from there ?
Thank you for your help.
As per my understanding you want to open "Welcome" Screen instead of "MainMenu"...
If you set launch screen in info.plist file, Welcome screen will be opened instead of MainMenu
Set this field in info.plist file :-
Launch screen interface file base name = Welcome
Hopefully it works for you.. Thanks
OK, I think I got it:
At the end of
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
I added:
[self.window orderOut:nil]; // hide application window
Welcome *welcome = [[Welcome alloc] initWithWindowNibName:@"Welcome"];
[welcome.window makeKeyAndOrderFront:self];
[[NSApplication sharedApplication] runModalForWindow:welcome.window]; // display splash screen
In my Welcome.m file, I added a close button on the splash window :
-(void)windowDidLoad
{
[super windowDidLoad];
NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:NSTitledWindowMask];
[closeButton setFrameOrigin:NSMakePoint(0, 410)];
NSView* contentView = self.window.contentView;
[contentView addSubview:closeButton];
[closeButton setTarget:[AppDelegate appDelegate]];
[closeButton setAction:@selector(closeModal:)];
}
And in AppDelegate.m, I added a closeModal method which is in charge of closing my welcome screen and display the application window:
-(void) closeModal:(id)sender
{
[[NSApplication sharedApplication] stopModal];
[self.window orderFront:nil];
}
Seems to work, maybe I should add something to discard my Welcome screen from memory too.