美文网首页
Attempted to read an unowned ref

Attempted to read an unowned ref

作者: 茗记西岭雪 | 来源:发表于2020-11-16 14:29 被阅读0次

    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 ref

          本文链接:https://www.haomeiwen.com/subject/mttzbktx.html