【问题标题】:My alertview for the UIWebView doesn't work我的 UIWebView 的警报视图不起作用
【发布时间】:2013-01-02 16:58:32
【问题描述】:

为什么这段代码不起作用?我只有这个:

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

应该可以吧?

【问题讨论】:

  • doesn't work 是什么意思,它会给出任何错误吗?你的 .h 文件中有 <UIAlertViewDelegate> 吗?
  • 另外,这与 Xcode 完全无关。
  • 我的 h 文件中没有
  • @user1941966 要接收 UIAlertViewDelegate 调用,例如didDismissWithButtonIndex:,您需要使用@interface myViewController : UIViewController <UIAlertViewDelegate>

标签: iphone uiwebview alertview


【解决方案1】:

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

_webview:didFailLoadWithError:

而这个方法的真名是

webView:didFailLoadWithError:

【讨论】:

  • 我改了,没变。
  • @user1941966 您是否尝试过同时进行两个更改? IE。我的和费尔南多·马松的?
【解决方案2】:

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

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

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

【讨论】:

  • 这并没有改变什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-04
  • 1970-01-01
  • 2014-11-18
  • 2015-10-19
  • 1970-01-01
相关资源
最近更新 更多