Cocoa WebView大型机方法返回nil
作为singleton特殊web浏览器的一部分,我在窗口控制器中有以下代码Cocoa WebView大型机方法返回nil,cocoa,macos,Cocoa,Macos,作为singleton特殊web浏览器的一部分,我在窗口控制器中有以下代码 + (id)sharedPurchaseController { static SomeController *sharedController = nil; if (!sharedController) { sharedController = [[SomeController alloc] initWithWindowNibName:@"anXIB"]; } ret
+ (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;
}
}
+(id)共享采购控制器{
静态SomeController*sharedController=nil;
如果(!sharedController){
sharedController=[[SomeController alloc]initWithWindowNibName:@“anXIB”];
}
返回共享控制器;
}
-(无效)从NIB中唤醒{
shouldReloadWeb=否;
[progressIndicator startAnimation:无];
NSString*urlText=[NSString stringWithString:@]http://www.google.com"];
[[webView大型机]加载请求:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]];
}
-(无效)窗口将关闭:(NSNotification*)通知{
shouldReloadWeb=是;
}
-(无效)windowDidBecomeKey:(NSNotification*)通知{
如果(应重新加载Web){
WebFrame*aFrame=[webView大型机];//默认情况下,当容器窗口关闭时,WebView
将关闭。当WebView
关闭时,它将卸载当前页面,停止加载任何当前请求,不再处理新请求,也不再发送委派消息。如果希望WebView
保持不变,以便在打开窗口时可以重新使用重新打开,你应该打电话
[webView setShouldCloseWithWindow:NO];
在-awakeFromNib
方法中