Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe several times #49

Closed
haitacnj opened this issue May 10, 2017 · 1 comment
Closed

Subscribe several times #49

haitacnj opened this issue May 10, 2017 · 1 comment

Comments

@haitacnj
Copy link

haitacnj commented May 10, 2017

I use tapGesture in TableView and it calls several times.

cell.ibPlaySound.rx.tapGesture().when(.recognized).subscribe(onNext: {   val  in
                print("play sound....")
}).addDisposableTo(self.binBag)

Touch once and call 3 (or 2) times
play sound....
play sound....
play sound....

@jegnux
Copy link
Member

jegnux commented May 10, 2017

@haitacnj Your cell is reusable, so everytime it's reused, you subscribe to it again. So the more it's reused, the more you will perform your subscribe onNext closure.

One solution could be to add a reusableBag in your cell subclass and clean it in prepareForReuse:

class MyCell: UITableViewCell {
    var reusableBag = DisposeBag()
    override func prepareForReuse() {
        super.prepareForReuse()
        reusableBag = DisposeBag()
    }
}

and add your disposeable in this bag:

cell.ibPlaySound.rx.tapGesture().when(.recognized).subscribe(onNext: { val in
print("play sound....")
}).addDisposableTo(cell.reusableBag)

PS: I close this as it's not really related to RxGesture, but feel free to reopen it if needed.

@jegnux jegnux closed this as completed May 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants