gpt4 book ai didi

ios - 从不兼容类型 'id _Nullable' 分配给 'WebView *const __strong'

转载 作者:行者123 更新时间:2023-11-28 19:33:03 25 4
gpt4 key购买 nike

当我在以下代码中将 webView.delegate = self; 添加到 WebView 时

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64)];
NSString *htmlFile = [[NSUserDefaults standardUserDefaults] objectForKey:USER_CODE];
NSLog(@"Value retured : %@",htmlFile);
NSURL *url = [NSURL URLWithString:htmlFile];
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:webView];
}

我收到以下错误。

/Applications/MAMP/htdocs/iOS/SchoolApp/test/WebView/WebView.m:25:22: Assigning to 'id<UIWebViewDelegate> _Nullable' from incompatible type 'WebView *const __strong'

最佳答案

您的 View Controller 没有实现 UIWebViewDelegate 协议(protocol)。不要在您的类的接口(interface)声明中包含它

@interface YourViewControllerName : UIViewController <UIWebViewDelegate>

关于ios - 从不兼容类型 'id<UIWebViewDelegate> _Nullable' 分配给 'WebView *const __strong',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41761665/

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