错误信息
Warning: Attempt to present <UIAlertController: 0x14f5a9e80> on <BrowserViewController: 0x14f5a7dd0> which is already presenting (null)
出现场景
我在一个界面中发送通知,接收通知界面的如下
notice.addObserver(forName: CertificationPhoto, object: nil, queue: .main) { (notin) in
if let isok = notin.userInfo?["Front"] as? Bool{
weak_self?.isFront = isok
showActionSheets(title: "提示", actionTitles: ["取消","相机","相册"]) { (row) in
if row == 1{
weak_self?.openCamera()
}else if row == 2{
weak_self?.openAlbum()
}
}
}
}
showActionSheets 是我封装的 UIAlertController
第一次进入这个VC界面各种弹出是正常的,关键是在此VC被释放后再重新打开,Alert弹出就直接此错误。
在网上查过:一种说法是弹出的 window.rootViewController?.presentedViewController != nil
需要先
window.rootViewController?.dismiss(animated: false, completion: nil)
再 window.rootViewController?.present(vc, animated: true, completion: nil)
感觉也没有冲突的存在,但还是试了一下此方法,发现确实不是这个问题。
分析
1、可能是有内存泄漏,通知二次计入,此界面没有接收到?
检查发现,确实存在没有正常释放的问题,解决了内存泄漏的问题。返回也能看到正常的页面销毁打印日志了。单问题并没有解决。
2、弱引用问题?
因为返回再主线程,考虑的就没有那么多,后来调试发现,再弹出提示之前,weak_self 为 nil
解决方法
notice.addObserver(forName: CertificationPhoto, object: nil, queue: .main) { (notin) in
if let isok = notin.userInfo?["Front"] as? Bool{
weak_self?.isFront = isok
weak_self?.showView()
}
}
func showView(){
showActionSheets(title: "提示", actionTitles: ["取消","相机","相册"]) { (row) in
if row == 1{
self.openCamera()
}else if row == 2{
self.openAlbum()
}
}
}
问题解决了。
网友评论