我一直在搜索论坛,但仍然不知道如何在webview中使用UIAlertController。 我发现了几个问题,虽然我没有真正得到解决方法。 如果你还不知道,我是个初学者。 我想要做的是,如果用户的互联网关闭,则会显示一条消息。 虽然我得到一个错误。 这是我得到的错误。
'WebViewController'没有可见的@interface声明选择器'presentedViewController:animated:completion:'
这里是我的代码在WebViewController的.m文件中。
- (void) webView:(UIWebView*) webView didFailLoadWithError:(nonnull NSError *)error { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Internet Connection" message:@"You don't have an internet connection! Please be aware that some pages might not load correctly." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *Okay = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:Okay]; [self presentedViewController:alert animated:YES completion:nil];}I've been searching on the forums and still don't really know how to use an UIAlertController in a webview. I found a couple of questions although I didn't really get how to fix it. I'm a beginner if you can't already tell. What I'm trying to do is, if the user's internet turns off a message shows up. Although I get an error. Here's the error I get.
No visible @interface for 'WebViewController' declares the selector 'presentedViewController:animated:completion:'
And here's my code in the WebViewController's .m file.
- (void) webView:(UIWebView*) webView didFailLoadWithError:(nonnull NSError *)error { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Internet Connection" message:@"You don't have an internet connection! Please be aware that some pages might not load correctly." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *Okay = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:Okay]; [self presentedViewController:alert animated:YES completion:nil];}最满意答案
你有一个错字 - 方法是presentViewController:animated:completion: ,not present**ed**ViewController:animated:completion: presentViewController:animated:completion: “礼物”是一个动词,而不是一个形容词 - 你要求自己做某件事,而不是某件事。 所以你收到的错误是完全正确的。
改成:
[self presentViewController:alert animated:YES completion:nil];You've a typo — the method is presentViewController:animated:completion:, not present**ed**ViewController:animated:completion:. The 'present' is meant to be a verb, not an adjective — you're asking yourself to do something, not about something. So the error you've received is completely correct.
Change to:
[self presentViewController:alert animated:YES completion:nil];更多推荐
发布评论