2
我的程序有两个类,第一个是常规应用程序代理NSObject
。第二个是NSWindowController
的子类,其上有NSWindow和WebView,它显示应用程序包中的HTML页面。WebView问题
这是我如何调用窗口从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即使嵌入特殊的新方法awakeFromNib
代码像-(void)refreshWebview
然后调用[webViewForm refreshWebview]
[webViewForm showWindow:self];
之后,还是 - ?加载页面只针对第一次,这是很奇怪的(任何想法