swift 中使用weak self

        button.rx.tap.subscribe({ [weak self] _ in
            self?.navigationController?.popViewController(animated: true)
        }).disposed(by: disposeBag!)

        button.rx.controlEvent(.touchUpInside).subscribe({ [weak self] _ in  //必须要加[weak self],否则释放不掉,不会执行deinit
                self?.navigationController?.popViewController(animated: true)
            })


不管用哪种方式,如果调用self,必须要写[weak self],要不会释放不掉的

猜你喜欢

转载自iaiai.iteye.com/blog/2406166