1
我正在使用RxSwift並開始創建一些基本的。我添加了新的按鈕,但是rx_tap訂閱不適用於按鈕操作。下面是我的代碼,請讓我知道我做錯了RxSwift不能與UIButton一起工作
let button = UIButton(frame: CGRect(x: 10, y: 66, width: 100, height: 21))
button.backgroundColor = UIColor.redColor()
button.setTitle("Login", forState: UIControlState.Normal)
let disposeBag = DisposeBag()
button.rx_tap
.subscribe { [weak self] x in
self!.view.backgroundColor = UIColor.redColor()
}
.addDisposableTo(disposeBag)
self.view.addSubview(button)
謝謝迪瑪,你可以請示例代碼相同,這將是非常好的幫助 – Kashif
移動'let disposeBag = DisposeBag()'出該函數和作爲包含類中的屬性聲明。只要做到這一點,就可以讓代碼的其他部分起作用。 – Dima
哇,它的作品像一個魅力,感謝您的幫助,我會永遠感謝,我對RxSwift很新,它使我很困惑。 – Kashif