从不兼容类型'WebView * const __strong'分配给'id <uiwebviewdelegate> _Nullable'

时间:2017-01-20 10:41:24

标签: ios objective-c webview

当我将 webView.delegate = self; 添加到以下代码中的网页视图时

None

我收到了以下错误。

- (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];
}

1 个答案:

答案 0 :(得分:3)

您的View控制器未实现 UIWebViewDelegate 协议。在您的类的接口声明中没有它

@interface YourViewControllerName : UIViewController <UIWebViewDelegate>