【发布时间】: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],仍然——页面仅是第一次加载,真的奇怪(有什么想法吗?
【问题讨论】: