Iphone UIWebView的我的alertview没有';行不通

Iphone UIWebView的我的alertview没有';行不通,iphone,uiwebview,alertview,Iphone,Uiwebview,Alertview,为什么这个代码不起作用?我所拥有的只是: -(void)_webview:(UIWebView *)_webview didFailLoadWithError:(NSError *)error { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"You have no internet connection!" delegate:self cancelButtonTitle:@"Clo

为什么这个代码不起作用?我所拥有的只是:

-(void)_webview:(UIWebView *)_webview didFailLoadWithError:(NSError *)error {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"You have no internet connection!" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    exit(0);
}

它应该可以工作,对吗?

因为您键入了
UIWebViewDelegate
方法的名称。你有

_webview:didFailLoadWithError:
而这种方法的真实名称是

webView:didFailLoadWithError:

委托方法键入错误,如上面的响应中所述。另外,您是否将UIWebView的委托设置为实现了这些方法的类的实例

例如,如果它是一个视图控制器,则它可能位于viewDidLoad中:

- (void)viewDidLoad
{
    [super viewDidLoad];
    _webView.delegate = self;
}

你所说的“代码”不起作用是什么意思,它会给出任何错误吗?您的.h文件中有
吗?另外,这与Xcode完全无关。我的h文件中没有。@user1941966要接收UIAlertViewDelegate调用,例如
didDismissWithButtonIndex:
您需要使用
@interface myViewController:UIViewController
我更改了它,没有任何更改。@user1941966您是否尝试同时进行这两项更改?即。我的和费尔南多·马佐恩的?那没有改变什么。