2
votes

My program have two classes, first of them is regular app delegate NSObject. The second one is a NSWindowController subclass with NSWindow and WebView on it, which shows html page from application bundle.

Here is how i call window from AppDelegate:

-(IBAction)showWebViewForm:(id)sender
{
    webViewForm = [[WebViewForm alloc] initWithWindowNibName:@"WebViewForm"];
    [webViewForm showWindow:self];
}

Here is how i render the webpage in WebViewForm : NSWindowController:

-(void)awakeFromNib{
    [NSApp activateIgnoringOtherApps:YES];
    [webview setUIDelegate: self];
    [webview setResourceLoadDelegate: self];
    [webview setPolicyDelegate:self];
    [webview setFrameLoadDelegate:self];

    [[webview mainFrame] loadRequest:
     [NSURLRequest requestWithURL:
      [NSURL fileURLWithPath:
       [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"data"]]]];

}

It's work fine, but only for the first time. When i close WebViewForm window and reopen it, webpage is disappearing from WebView. Why is so that, and how to fix it?

UPD Even if embed awakeFromNib code in special new method like -(void)refreshWebview and then call [webViewForm refreshWebview] right after [webViewForm showWindow:self];, still — page loads only for first time, and it's really weird ( Any ideas?

1

1 Answers

3
votes

I figure it out by myself. The problem was, that webview closed when it's parent window closed. So, there is special method for case like that:

[webview setShouldCloseWithWindow:NO];