[英]Why Animation doesn't work inside a child view passed by Binding?
[英]Why doesn't the subscription of the relay work even though there is a value passed to it?
我已经设置了这样的relay
:
class CustomAlertViewController: UIViewController {
private let disposeBag = DisposeBag()
var alertTextRelay = BehaviorRelay<String>(value: "")
alertTextField.rx.value.orEmpty.changed.subscribe(onNext: { [weak self] value in
print("THIS IS RIGHT", value)
self?.alertTextRelay.accept(value)
print("THIS IS ALSO RIGHT", self?.alertTextRelay.value)
}).disposed(by: disposeBag)
...
我得到在textField
写入的文本并将其接受到relay
并检查以确保该值确实存在。 但订阅永远不会触发:
class RecievingClass: UIViewController {
let disposeBag = DisposeBag()
let instance = CustomAlertViewController()
instance.alertTextRelay.subscribe(onNext: { value in
self.myText = value
}, onError: { error in
print(error)
}, onCompleted: {
print("completed")
}).disposed(by: disposeBag)
...
subscription
没有任何内容被触发。 为什么? 如果有帮助, CustomAlertViewController
将用作自定义alert
(叠加层上的view
)。 此外, CustomAlertViewController
中有很多static
函数。 不确定这是否相关。 如果我能提供其他任何东西,请告诉我。
尝试在此 alertTextField.rx.text.orEmpty.asObservable() 上更改此 alertTextField.rx.value.orEmpty.changed.subscribe。 并以其他方式为 RecievingClass 添加 [weak self] 会导致内存泄漏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.