不调用 UIWebView webViewDidStartLoad 和完成

UIWebView webViewDidStartLoad and finish is not called

我已经多次看到这个问题出现在这个网站上,但是 none 的答案对我很有帮助。其他问题的答案就是像这样将web视图的delegate设置为self

WebView.delegate = self

然而,当我这样做时,它给我错误

"cannot assign a value of type 'MainScreen' to a value of type 'UIWebViewDelegate?'

所以我在打字的时候想出了答案,但我还是决定 post 以防万一有人遇到我遇到的同样问题。

解决方案是您必须像这样将 "UIWebViewDelegate" 添加到您的视图控制器

class MainScreen : UIViewController, UIWebViewDelegate {