【问题标题】:WebView action when view did not load (Cocoa OS X)视图未加载时的 WebView 操作(Cocoa OS X)
【发布时间】:2015-01-09 19:47:37
【问题描述】:

您好,有没有办法在无法加载视图时以编程方式显示 NSAlert,我正在尝试制作一个加载 Web 服务器的 WebView,当服务器不在线时,我希望显示 NSAlert .我已经走到这一步了

-(void)checkView{

    if(webView ???????){
    NSString *server = ipbox.stringvalue;

    [[NSAlert alertWithMessageText:@"The Server is offline" defaultButton:@"OK" alternateButton:@"" otherButton:@"" informativeTextWithFormat:@"The server %@ is down", server] runModal];    

    }

    else{
      nil;
    }
}

我不知道在“如果”部分放什么。我试过 webViewDid 但 OS X 中没有 webViewDidLoad。所以基本上我正在寻找类似“视图加载失败”之类的东西,谢谢。

【问题讨论】:

    标签: objective-c macos cocoa webview alert


    【解决方案1】:

    可以使用委托方法:

    -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    
        //NSLog(@"%@", error);
        [[NSAlert alertWithMessageText:@"The Server is offline" defaultButton:@"OK" alternateButton:@"" otherButton:@"" informativeTextWithFormat:@"The server %@ is down", server] runModal];    
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多