懒加载wkwebview,在viewdidload中调用偶尔会crash

懒加载中用masonry定义wbwebview的布局,


在viewdidload中loadrequest,偶尔会crash,错误如下:

[Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior ()

2017-08-09 11:40:44.631248 caishen[7432:2496466] *** Assertion failure in -[MASViewConstraint setSecondViewAttribute:], 

断点定位在[MASViewConstraint setSecondViewAttribute]


抓耳挠腮头疼脑热之后才恍然大悟,在viedidload是,self.view有可能是nil,而此时让wkwebview去loadrequest会执行懒加载方法,masonry设定布局是找不到self.view必然就crash了.

解决办法:在viewwillappear中让wkwebview loadrequest

你可能感兴趣的:(懒加载wkwebview,在viewdidload中调用偶尔会crash)