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)

你可能感兴趣的:(Attempted to read an unowned reference but the object was already deallocated Fatal error: Attem...)