Getting Windows to Appear.....


Dave
 

Hi All,

I’m having problems getting a window to appear on the Mac.

This is the first time I’ve used Storyboards on the Mac and I’m not sure I have things setup correctly.

When I created the project I used the single window application template which gave me a Main.storyboard with a Window and View Controller setup. I’m now trying to add the main game window to the App which is in a separate storyboard as it uses Manual Layout. The Window that XCode created I’ve called “Game Setup” and the Window I’ve just added, “Game”. I tried making the Game window the initial window, but this doesn’t seem to do anything.

Ultimately the way I want this to work is for a “Game Setup” window to appear which then opens the Main Game window after the user has had a chance to tweak the settings. For now, I just want the Game Setup window to open and present the Main Game Window.

I added this code to the setup window:

-(void) viewDidAppear
{
NSStoryboard* myStoryboard;
NSWindowController* myGameWindowController;

//**
//** Instantiate the Game Window Controller
//**
myStoryboard = [NSStoryboard storyboardWithName:@"MacManualLayout" bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:@"LTWGameWindowController1"];
if (myGameWindowController == nil)
return;

//**
//** Present the Game Window
//**
[myGameWindowController showWindow:nil];

// [myGameWindowController.window orderFront:nil]; //Tried this, but made no difference.
}

myGameWindowController has a View Controller in it in the Storyboard and its being ok as I’ve put a breakpoint in viewDidAppear and it fires ok. However, I just have the Startup window and no Game Window showing. Is there something more I have to do to make it appear?

All the Best
Dave


Quincey Morris
 

On Aug 29, 2017, at 08:54 , Dave <dave@...> wrote:

-(void) viewDidAppear
{
NSStoryboard* myStoryboard = [NSStoryboard storyboardWithName:@"MacManualLayout" bundle:nil];
NSWindowController* myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:@"LTWGameWindowController1"];
[myGameWindowController showWindow:nil];
}

(code edited to get rid of the noise)

That’s what you’re doing, really? The window controller you create here has no owning references outside this method’s local variable, so it’s going to disappear as soon as this method returns, taking the window with it into oblivion.


Dave
 

Hi,

Yeah, realised that afterwards, I made it a property for now, it will be retained by the App Manager once I add it,

Cheers
Dave

On 29 Aug 2017, at 19:16, Quincey Morris <quinceymorris@...> wrote:

On Aug 29, 2017, at 08:54 , Dave <dave@...> wrote:

-(void) viewDidAppear
{
NSStoryboard* myStoryboard = [NSStoryboard storyboardWithName:@"MacManualLayout" bundle:nil];
NSWindowController* myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:@"LTWGameWindowController1"];
[myGameWindowController showWindow:nil];
}

(code edited to get rid of the noise)

That’s what you’re doing, really? The window controller you create here has no owning references outside this method’s local variable, so it’s going to disappear as soon as this method returns, taking the window with it into oblivion.