当我添加webView.delegate = self;通过以下代码访问网络视图

- (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控制器未实现UIWebViewDelegate协议。请勿在类的接口声明中使用它

@interface YourViewControllerName : UIViewController <UIWebViewDelegate>

10-08 06:26