Pushing the same view controller instance more than once is not supported,发现这个问题是因为看了友盟的错误分析才发现,一般还真的不好重现,也许影响的用户可能也就两三个,但是为了用户体验,发现了这个问题还是要解决的。
猜测就是以下情况:
let showTest = TestVC()
self.navigationController?.pushViewController(showTest, animated: true)
self.navigationController?.pushViewController(showTest, animated: true)
解决方案(其一)
class YQLNavigationController: UINavigationController, UINavigationControllerDelegate {
var isSwitching: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
// print("开始push")
//算是为了解决一个问题吧Pushing the same view controller instance more than once is not supported
if self.isSwitching == true {
return;
}
super.pushViewController(viewController, animated: animated)
}
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
self.isSwitching = false
// print("视图控制器已经显示")
}
}