Cocoa 网络视图问题
我的程序有两个类,第一个类是常规应用程序委托Cocoa 网络视图问题,cocoa,macos,Cocoa,Macos,我的程序有两个类,第一个类是常规应用程序委托NSObject。第二个是一个NSWindowController子类,上面有NSWindow和WebView,它显示应用程序包中的html页面 以下是我如何从AppDelegate调用窗口: -(IBAction)showWebViewForm:(id)sender { webViewForm = [[WebViewForm alloc] initWithWindowNibName:@"WebViewForm"]; [webViewF
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即使在特殊的新方法中嵌入
awakeFromNib
代码,如-(void)refreshWebview
,然后在[webViewForm showWindow:self]之后立即调用[webViewForm refreshWebview]
代码>,仍然是第一次加载页面,这真的很奇怪(有什么想法吗?我自己想出来的。问题是,webview在父窗口关闭时关闭了。因此,对于这种情况,有一种特殊的方法:
[网络视图设置应关闭窗口:否];