【发布时间】:2021-01-11 13:28:44
【问题描述】:
我有一个与rx 挂钩的UISwitch。每当它被切换时,就会显示一个alertView。如果选择 ok 会发生一些事情,但如果按下取消,则不会发生任何事情,UISwitch 将保持在同一个位置,即它没有被切换。
mySwitch.rx.controlEvent(.valueChanged).subscribe(onNext: { [weak self] _ in
guard let self = self else { return }
CustomAlertViewController.standardTwoButtonMessageAlert(title: self.mySwitch.isOn ? "Do you want to turn this on?" : "Do you want to turn this off?", msg: "hello", action: {
print("Doing stuff")
}, cancelAction: {
//SHOULD NOT TOGGLE
})?.present(animated: true, onView: UIApplication.topViewController())
}).disposed(by: disposeBag)
还有一个问题是当我到达cancelAction 时UISwitch 已经被切换,这意味着它需要再次切换回来。如何切换回来?有没有办法完全阻止它切换,以便我可以在闭包内手动管理它?
【问题讨论】:
标签: ios swift rx-swift uialertcontroller uiswitch