Re: Properties being set to nil?


Dave
 

Looking at the log (and reformatting it a bit):

initWithCoder: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
viewDidLoad: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>

initWithCoder: <LTWMacGameViewController: 0x60000350d4a0>
awakeFromNib: <LTWMacGameViewController: 0x60000350d4a0>
setGameCommandDelegate: <LTWMacGameViewController: 0x60000350d4a0>

viewWillAppear: <LTWMacGameViewController: 0x600003514370>
viewDidAppear: <LTWMacGameViewController: 0x600003514370>

catchBug: <LTWMacGameViewController: 0x60000350d4a0>

So it looks like the 0x600003514370 instance is the good one and 0x60000350d4a0 the imposter!

On 16 Jan 2020, at 19:38, Dave <dave@...> wrote:

Hi Jon,

Can you just set an outlet to point to the instance loaded from your storyboard and leave it from that (that's what you should be doing unless you need multiple instances of LTWGameViewController in your app).

I’m not sure what you mean? Do you mean an outlet to the LTWGameViewController in the StartupWindowController?

Here’s what I am doing:

In AppDelegate::applicationDidFinishLaunching

myStoryboard = [NSStoryboard storyboardWithName:kLTWStartupStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWStartupWindowControllerID];
if (myGameWindowController == nil)
{
return;
}
self.pStartupWindowController = myGameWindowController;

[myGameWindowController showWindow:nil];

----------------------

In the StartupViewController:


-(void) viewDidAppear
{
NSStoryboard* myStoryboard;
NSWindowController* myGameWindowController;
LTWMacGameViewController* myGameViewController;
NSString* myGameID;
LTWSudokuAppManager* myAppManager;

//**
//** Instantiate the Game Window Controller
//**
myStoryboard = [NSStoryboard storyboardWithName:kLTWGameStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainWindowControllerID];
if (myGameWindowController == nil)
{
return;
}

//**
//** Instantiate the Game View Controller
//**
myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

//**
//** Create a New Game  
//**
myGameID = [self.pSingletonManager.pSudokuAppManager newGameWithReportDelegate:myGameViewController];

//**
//** Set the Game View Controller Delegates
//**
myAppManager = self.pSingletonManager.pSudokuAppManager;
[myGameViewController setGameControlDelegate:[myAppManager getGameControlDelegate]];
[myGameViewController setGameCommandDelegate:[myAppManager getGameCommandDelegate]];

self.pGameViewController = myGameViewController;
self.pGameWindowController = myGameWindowController;
[self.pGameWindowController showWindow:nil];

//**
//** Close the Startup Window
//**
[self.view.window close];


————————————————————

When I run I get this in the log:

initWithCoder: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
viewDidLoad: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
initWithCoder: <LTWMacGameViewController: 0x60000350d4a0>
awakeFromNib: <LTWMacGameViewController: 0x60000350d4a0>
setGameCommandDelegate: <LTWMacGameViewController: 0x60000350d4a0>
viewWillAppear: <LTWMacGameViewController: 0x600003514370>
viewDidAppear: <LTWMacGameViewController: 0x600003514370>
catchBug: <LTWMacGameViewController: 0x60000350d4a0>

catchBug is a method that gets called after a delay after the delegate is set.

So it does look like there are 2 instances!


Cheers
Dave



On 16 Jan 2020, at 19:06, Jon Gotow <gotow@...> wrote:

On Jan 16, 2020, at 10:48 AM, Dave <dave@...> wrote:

Yes, LTWGameViewController is a subclass of NSViewController and I set the Class in the Storyboard. 

When I set a breakpoint in the Set Delegate method it shows the property set ok. Later on it responds to an IBAction and its set to nil. It certainly looks like there are 2 objects! Is this a bug? Is there a work-around?

The fact that you've got two instances of your LTWGameViewController certainly sounds like a bug. It's difficult to tell without looking at your whole project, but my guess is that you've got one instance loaded from the storyboard, and then you're creating a second one programmatically later. Can you just set an outlet to point to the instance loaded from your storyboard and leave it from that (that's what you should be doing unless you need multiple instances of LTWGameViewController in your app).

- Jon






Join cocoa@apple-dev.groups.io to automatically receive all group messages.