Attempted to read an unowned reference but the object was already deallocated Fatal error: Attem...

Attempted to read an unowned reference but the object was already deallocated

Fatal error: Attempted to read an unowned reference but the object was already deallocated

        loginBtn.rx.tap.subscribe {[unowned self] (_) in
            let alert = UIAlertController(title: "提示", message: "登录成功!", preferredStyle: .alert)
            let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
            alert.addAction(ok)
            self.present(alert, animated: true, completion: nil)
        }.disposed(by: disposBag)

页面返回的时候 崩溃在了

self.present(alert, animated: true, completion: nil)

更改如下解决了

        loginBtn.rx.tap.subscribe {[weak self] (_) in
            let alert = UIAlertController(title: "提示", message: "登录成功!", preferredStyle: .alert)
            let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
            alert.addAction(ok)
            self?.present(alert, animated: true, completion: nil)
        }.disposed(by: disposBag)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容