Pushing the same view controller instance more than once is not supported

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("视图控制器已经显示")
    }


}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容