4
我在窗口控制器以下代碼作爲一個單專用web瀏覽器的一部分web視圖的mainFrame方法返回零
+ (id)sharedPurchaseController {
static SomeController *sharedController = nil;
if (!sharedController) {
sharedController = [[SomeController alloc] initWithWindowNibName:@"anXIB"];
}
return sharedController;
}
- (void)awakeFromNib{
shouldReloadWeb = NO;
[progressIndicator startAnimation:nil];
NSString* urlText = [NSString stringWithString:@"http://www.google.com"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
}
-(void)windowWillClose:(NSNotification *)notification{
shouldReloadWeb = YES;
}
- (void)windowDidBecomeKey:(NSNotification *)notification{
if (shouldReloadWeb){
WebFrame* aFrame = [webView mainFrame]; //<-- Returns nil second time
[[webView mainFrame] reload];
shouldReloadWeb = NO;
}
}
的問題是,當NSWindow(瀏覽器)被關閉,然後重新打開,第二次,[webView mainFrame]
返回零。 NSWindow出現在屏幕上,但WebView不響應。
如果我註釋掉創建單例的代碼,一切都按預期工作。
有沒有用Web應用程序創建一個單獨的瀏覽器,同時保持WebView在Nib中?
感謝,-Ben
+1今天剛剛有這個問題。有一些超級遲到的提議。 – Dominic