【问题标题】:WebView problemWebView 问题
【发布时间】:2011-08-09 08:19:31
【问题描述】:

我的程序有两个类,第一个是常规应用程序委托NSObject。第二个是 NSWindowController 子类,上面有 NSWindow 和 WebView,它显示了来自应用程序包的 html 页面。

这是我从 AppDelegate 调用窗口的方式:

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

这是我在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"]]]];

}

它工作正常,但只是第一次。当我关闭 WebViewForm 窗口并重新打开它时,网页将从 WebView 中消失。为什么会这样,如何解决?

UPD 即使在-(void)refreshWebview 等特殊的新方法中嵌入awakeFromNib 代码,然后在[webViewForm showWindow:self]; 之后立即调用[webViewForm refreshWebview],仍然——页面仅是第一次加载,真的奇怪(有什么想法吗?

【问题讨论】:

    标签: cocoa macos


    【解决方案1】:

    我自己想办法。问题是,当它的父窗口关闭时,webview 关闭了。因此,对于这种情况,有一种特殊的方法:

    [webview setShouldCloseWithWindow:NO];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2019-05-16
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多