2013-01-02 29 views
1

为什么这个代码不工作?我所有的是这样的:我的UIWebView的alertview不起作用

-(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); 
} 

它应该工作,对不对?

+0

什么叫'并不意味着work',没有给出任何错误?你的.h文件中有吗? –

+0

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html –

+0

此外,这绝对与Xcode无关。** – 2013-01-02 17:06:21

回答

0

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

_webview:didFailLoadWithError: 

,而这种方法的真名是

webView:didFailLoadWithError: 
+0

我改变了它,没有任何改变。 – user1941966

+0

@ user1941966您是否尝试过**同时进行**更改? I. e。我和Fernando Mazzon的? – 2013-01-02 17:20:33

+0

是的。不用找了。 – user1941966

0

委托方法是拼写错误,如上面的答复中指出。另外,你是否将UIWebView的委托设置为实现了这些方法的类的实例?

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

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

这并没有改变任何东西。 – user1941966