Opening a "Welcome" window from main application window - objective-c

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.

Related

Xcode storyboard how to detect touch item

I have a storyboard setup (the default) with the tabbed application template.
I want to add a BarItem and have that launch a URL when touched. I don't want it to go to a view in the app. How can I do this using the storyboard?
I am new the story board concept and not sure what to add to the story board to add a new bar item and then make it call a method.
First you need to put a function in the ViewController code something like...
- (IBAction)barButtonPressed:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
Then go add the button to the view controller in the Storyboard and ctrl click drag from the button to the function.
This will make the button run that function when pressed.
If you mean the Navigation bar
//in viewDidLoad or wherever
UIBarButtonItem *openWebLink = [[UIBarButtonItem alloc]
initWithTitle: #"OpenWebLink"
style: UIBarButtonItemStyleBordered
target: nil action: #selector(openLink)];
[self.navigationItem setBackBarButtonItem: openWebLink];
-(void) openLink
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
If you don't, look at Fogmeister answer
Code not tested!

Improper setup of window displayed through menu item?

I am working on my first native mac app after playing with iOS for a while.
I am attempting to launch a window from a menu item, but I suspect I am doing it wrong. Any IBAction I connect to buttons on this new window returns an error.
Here is what I am doing. From a menu item I launch this:
-(IBAction)displaySAInput:(id)sender{
NSLog(#"Input selected.");
inputSAViewController = [[NSWindowController alloc] initWithWindowNibName:#"InputViewController"];
[inputSAViewController showWindow:self];
This launches the InputViewController nib that is owned by the InputViewController class. I set the InputViewController class to inherit from NSWindowController.
On InputViewController.m I have tested IBActions such as:
-(IBAction)testButton:(id)sender{
NSLog(#"Data recalled?");
}
I connect this IBAction to a button through the Interface Builder. All looks okay.
When I build and open the InputViewController window I receive this error in the console before clicking anything:
Could not connect the action testButton: to target of class NSWindowController
I have searched extensively but my ignorance prevents me from connecting the dots. This thread based on a similar error with NSApplication looks promising, but I don't quite understand what I'd need to make the connections happen related to the NSWindowController error.
This should be simple. What am I missing?
Your code:
-(IBAction)displaySAInput:(id)sender{
NSLog(#"Input selected.");
inputSAViewController = [[NSWindowController alloc]
initWithWindowNibName:#"InputViewController"];
[inputSAViewController showWindow:self];
}
Notice you are alloc/initing a generic instance of NSWindowController, not your custom subclass where you've implemented the testButton: method. I assume you'd likely want that changed to:
-(IBAction)displaySAInput:(id)sender{
NSLog(#"Input selected.");
inputSAViewController = [[InputViewController alloc]
initWithWindowNibName:#"InputViewController"];
[inputSAViewController showWindow:self];
}
Just load the NSWindow before hand and make it invisible and when the IBAction is called, just do the following:
[myWindow setIsVisible:YES];
[myWindow setLevel:NSFloatingWindowLevel];
Yay!

App stuck on runModalForWindow

I'm trying to display a modal dialog on top of my app but it's blocking my main app window when it closes. Here's my code:
TutorialWindowController* pTutorialController = [[TutorialWindowController alloc] initWithWindowNibName:#"TutorialWindow"];
NSWindow* pTutorialWindow = [pTutorialController window];
DDLogInfo(#"Tutorial window opening...");
[NSApp runModalForWindow: pTutorialWindow];
DDLogInfo(#"Tutorial window closed!"); // CODE NEVER GETS HERE
[NSApp endSheet: pTutorialWindow];
[pTutorialWindow orderOut: self];
In the modal dialog, my Close button runs this:
- (IBAction)closeButtonPressed:(id)sender {
[NSApp stopModal];
}
The modal dialog displays fine. However, when I click the Close button, the dialog disappears and my app's main window isn't responsive. I hear the bonk every time I try clicking. I'm pretty sure this is because the code never continues after runModalForWindow. Same thing happens if I close the modal dialo using the red X.
What am I doing wrong?
After ordering out the tutorial window, try doing a
[window makeKeyAndOrderFront:self];
on your main window.
You should call [pTutorialWindow orderOut:nil] first.
Not sure about the closeButtonPressed handler. But try adding to the delegate:
- (void) windowWillClose:(NSNotification *)notification
{
// ...
// In there, you should verify that you are calling:
[NSApp stopModal]
}
Adding the stopModal call solved the issue for me.
Verify that the Window delegate in the Interface Editor's Connection Inspector is connected to the File's Owner.
I had several modal dialogues working correctly except for one, and the missing connection was the only difference. Making the connection fixed the problem.

iPad SplitView Application not taking up entire window

I am working on a split-view based application for the iPad. I created a menu overlay system that has a button that leads into the split-view application. See comment for image
When you click the enter button, however, it results in this:
http://commandoswat.webs.com/Screen%20shot%202010-09-16%20at%201.37.11%20PM.png
Here is my code for the application delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
mainMenuController = [[MainMenuController alloc]init];
mainMenuController.sWindow = window;
mainMenuController.sController = splitViewController;
// Add the split view controller's view to the window and display.
[window addSubview:mainMenuController.view];
[window makeKeyAndVisible];
return YES;
}
Here is my code for the MainMenuController Enter Button:
-(IBAction) enterButton{
[self.view removeFromSuperview];
[sWindow addSubview:sController.view];
}
How do I make the split view take up the entire screen?
Any suggestions?
Thanks
Looks to me that your detail view isn't sized properly, and/or doesn't have its autoresizingMask property set appropriately (to have flexible width).

Loading NIB using [NSBundle loadNibNamed:owner:] but the window does not appear in the foreground

I wrote a menu application that has no persistent window or standard menu. When another application has focus and I use the menulet to trigger a window to be opened, it appears behind the foreground application (but above anything else that is present on the screen).
Basically...
-(IBAction)aboutWindow:(id)sender {
[NSBundle loadNibNamed:#"About" owner:self];
}
Can anyone point me in the right direction so I can get this window to appear above all other applications when it is initially spawned?
[Edit]
I have tried using a custom NSWindowController with the window linked up, and awakeFromNib calling a makekeyandorderfront method, but that wasn't doing anything.
I now have instead of the NSBundle call:
NSWindowController* awc = [[NSWindowController alloc] initWithWindowNibName:#"About"];
[[awc window] makeKeyAndOrderFront:nil];
And that spawns the window, but still does not make it in the foreground
Figured it out. Nothing was wrong with the Window, it was the Application. It was not in the foreground because of its nature as a menulet with no windows before this one is spawned. Final code:
-(IBAction)aboutWindow:(id)sender {
NSWindowController* awc = [[NSWindowController alloc] initWithWindowNibName:#"About"];
[[awc window] makeKeyAndOrderFront:nil];
[[NSApplication sharedApplication] arrangeInFront:nil];
}
You could try makeKeyAndOrderFront:
For example, in the About window's controller - assuming the controller had a reference to the window as myWindow:
- (void)awakeFromNib
{
[myWindow makeKeyAndOrderFront:nil];
}