如何在webview中创建UIAlertController?(How do I create a UIAlertController in a webview?)

编程入门 行业动态 更新时间:2024-10-18 18:22:48
如何在webview中创建UIAlertController?(How do I create a UIAlertController in a webview?)

我一直在搜索论坛,但仍然不知道如何在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];

更多推荐

本文发布于:2023-08-04 07:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   webview   create   UIAlertController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!