WKNavigationDelegate 仅在代码中设置断点时调用

问题描述

我遇到了 WKWebview 和导航委托的问题。 如果我在没有断点的情况下执行应用程序,则永远不会调用委托。如果我在创建 webview 之后在某处设置了断点,并且调用了 loadHtmlString 方法,那么委托就会被正确调用。

以下是我正在做的事情的简化版本:

//This custom view is part of a ViewController where the user interface was designed
// using the storyboardeditor
class CustomContainerView:UIView{
         @IBOutlet weak var viewContainer: UIView!
        
        public func render(){
        
                let behaviour: IViewBehaviour = self.getBehaviour(slice) //In this case,the behaviour is an instance of the class BehaviourN3
                let view = behaviour.getView() //In this case the returned view is a WKWebView
        
                viewContainer.addSubview(view)
                view.bindFrameToSuperviewBounds(0)
                behaviour.render()
        
        }
        }
    }
        
     public class BeahviourN3: BaseBehaviour,WKNavigationDelegate{
            
             internal var webView: WKWebView!
            
                required init() {
                   
                    webView = createWebView()
            
                    
            
                }
            
            override func getView() -> UIView {
                    return webView
                }
            
            
             override func render() {
                    
                   webView.navigationDelegate = self
        // If I set a breakpoint before calling the loadHtmlString method,and wait a couple of seconds then the 
        // delegate is called succesfully
        
                   webView.loadHTMLString(html,baseURL: myBaseUrl)
                }
            
            
            }
            
            
              public func webView(_ webView: WKWebView,didFinish navigation: WKNavigation!) {
                    self.evaluateBodyHeight()
              }
            
            }

我知道如果没有显示视图,则不会调用 WKWebView 的导航委托(我过去遇到过这个问题)。但在本例中,webview 被添加到一个正在显示和可见的视图容器中。

我想在设置断点时,操作系统有更多的时间来做它的事情,不知何故这会有所作为,但我不知道如何解决这个问题。

有什么想法吗?

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...