Objective c 从UIWebView中的缓存页面单击链接时,如何显示连接错误?

Objective c 从UIWebView中的缓存页面单击链接时,如何显示连接错误?,objective-c,xcode,ios5,Objective C,Xcode,Ios5,我正在开发一个带有UIWebView的应用程序,它只显示一个页面,我们称之为http://myPage.com——上面有几个链接。当用户第一次单击导致http://myPage.com没有问题。但是如果没有连接,并且用户单击go to myPage按钮,则不会获得任何UIAlertView,因为http://myPage.com返回,然后尝试跟随http://myPage.com,什么也没发生。在这种情况下,如何重写或添加代码以显示警报 这是我的密码: -(void)loadWebViewWit

我正在开发一个带有
UIWebView
的应用程序,它只显示一个页面,我们称之为
http://myPage.com
——上面有几个链接。当用户第一次单击导致
http://myPage.com
没有问题。但是如果没有连接,并且用户单击go to myPage按钮,则不会获得任何
UIAlertView
,因为
http://myPage.com
返回,然后尝试跟随
http://myPage.com
,什么也没发生。在这种情况下,如何重写或添加代码以显示警报

这是我的密码:

-(void)loadWebViewWithbaseURLString:bus withURLString:us
{
self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:us] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 20];
self.connection=[[NSURLConnection alloc] initWithRequest:self.request delegate:nil];
NSError *error=nil;
NSURLResponse *response=nil;
if (self.connection)
{
    self.urlData = [ NSURLConnection sendSynchronousRequest: self.request returningResponse:&response error:&error];
    NSString *htmlString = [[NSString alloc] initWithData:self.urlData encoding:NSUTF8StringEncoding];
    [self.webV loadHTMLString:htmlString baseURL:[NSURL URLWithString:bus]];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] init];
    alert.title = @"Unfortunately, I seem to be having a hard time connecting to the Internet.  Would you mind trying again later?  I'll make it worth your while, I promise.";
    [alert show];
}
}

当然,go to myPage代码只是调用
-(void)loadWebViewWithbaseURLString:bus withURLString:us
,并将特定URL作为参数。

我在上以更清晰(我希望)的方式问了这个问题,最终我自己也能解决,所以我发布了答案