gpt4 book ai didi

ios - setDelegate 上的语义问题

转载 作者:行者123 更新时间:2023-11-29 03:53:44 25 4
gpt4 key购买 nike

我的代码存在语义问题。我有一个 UIWebView,并且添加了一条错误消息,因此如果没有互联网连接,则会弹出错误。

这是我的 .m 文件中 UIWebView 的编码

- (void)viewDidLoad {
[super viewDidLoad];
NSString *fullURL = @"http://example.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[website setDelegate:self];
[website loadRequest:requestObj]; }

此代码有错误

[website setDelegate:self];

它说这是一个语义问题,错误是发送 FirstViewController *const_strong 到不兼容类型 id 的参数

这里是没有互联网连接时出现错误消息的代码

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" message:@"error connecting to the internet" delegate:self
cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show]; }

最佳答案

您需要指定 FirstViewController 实现协议(protocol)。像这样的东西:

@interface FirstViewController ()  <UIWebViewDelegate>
@end

编译器当前警告您,您正在设置一个委托(delegate),但未指定它实现所需的协议(protocol),因此不会执行任何编译检查。

关于ios - setDelegate 上的语义问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16763861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com