I have the following code in a window controller as part of a singleton special web browser
+ (id)sharedPurchaseController {
static SomeController *sharedController = nil;
if (!sharedController) {
sharedController = [[SomeController alloc] initWithWindowNibName:@"anXIB"];
}
return sharedController;
}
- (void)awakeFromNib{
shouldReloadWeb = NO;
[progressIndicator startAnimation:nil];
NSString* urlText = [NSString stringWithString:@"http://www.google.com"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
}
-(void)windowWillClose:(NSNotification *)notification{
shouldReloadWeb = YES;
}
- (void)windowDidBecomeKey:(NSNotification *)notification{
if (shouldReloadWeb){
WebFrame* aFrame = [webView mainFrame]; //<-- Returns nil second time
[[webView mainFrame] reload];
shouldReloadWeb = NO;
}
}
The problem is that when the NSWindow (browser) is closed and then re-open, for a second time, [webView mainFrame]
returns nil. The NSWindow appears on screen, but the WebView is non-responsive.
If I comment out the code that creates a singleton, everything works as expected.
Is there away to create a singleton browser with an application while keeping the WebView in the Nib?
Thanks, -Ben