ios - RxSwift not working with UIButton -
i working on rxswift , started creating few basic. have added new button rx_tap subscribe not working button action. below code, please let me know doing wrong
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)
your subscription cancelled because of scope of disposebag
. created, goes out of scope , deallocated. need retain bag somewhere. if using view controller or that, can create property there , assign that.
Comments
Post a Comment