Ios 添加子视图时EXC_错误_访问代码1
这个错误不会发生在模拟器中,而是发生在我的手机上。我有5个不同的网络视图,我有一个菜单设置,这样当选择一个时,它将作为子视图添加,其他网络视图将从superview中删除Ios 添加子视图时EXC_错误_访问代码1,ios,swift,subview,Ios,Swift,Subview,这个错误不会发生在模拟器中,而是发生在我的手机上。我有5个不同的网络视图,我有一个菜单设置,这样当选择一个时,它将作为子视图添加,其他网络视图将从superview中删除 // MARK: - Hides all other webviews and shows selected func hideOtherWebViews(selectedWebView: WKWebView!){ self.navBarFixed = false dispatch_async(dispatch
// MARK: - Hides all other webviews and shows selected
func hideOtherWebViews(selectedWebView: WKWebView!){
self.navBarFixed = false
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if checkLoaded.currentWebView != self.selectedWeb{
for webview in [self.facebookWeb, self.instagramWeb, self.googleplusWeb, self.twitterWeb, self.youtubeWeb, self.linkedinWeb]{
// If it isn't the selected web view do this
if webview != selectedWebView{
webview.removeFromSuperview()
println("web hidden")
// If it is the selected web view do this
}else{
self.centerView.addSubview(webview)
webview.setTranslatesAutoresizingMaskIntoConstraints(false)
//webview constraints
let top = NSLayoutConstraint(item: webview, attribute: .Top, relatedBy: .Equal, toItem: webview.superview, attribute: .Top, multiplier: 1, constant: 0)
let right = NSLayoutConstraint(item: webview, attribute: .Right, relatedBy: .Equal, toItem: webview.superview, attribute: .Right, multiplier: 1, constant: 0)
let left = NSLayoutConstraint(item: webview, attribute: .Left, relatedBy: .Equal, toItem: webview.superview, attribute: .Left, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: webview, attribute: .Bottom, relatedBy: .Equal, toItem: webview.superview, attribute: .Bottom, multiplier: 1, constant: 0)
self.view.addConstraints([ top, right, left, bottom])
webview.scrollView.delegate = self
webview.navigationDelegate = self
webview.UIDelegate = self
webview.scrollView.showsHorizontalScrollIndicator = false
webview.scrollView.showsVerticalScrollIndicator = false
self.whiteOverlay.alpha = 1
UIView.animateWithDuration(0.2, animations: { () -> Void in
self.whiteOverlay.alpha = 0
})
}
}
}
})
错误发生在
self.centerView.addSubview(webview)
中断调试器并查看哪个对象导致错误访问。self、centerview或web view(使用“po”命令)--我怀疑centerview由于您调度async,是不是您过早地取消分配了任何内容您可以显示webView的属性,如
self.facebookWeb
,…?@Daij Djan是的,是centerview导致了错误access@user3796209当前位置我现在面临同样的问题。