ios開発に置いて、RxSwiftを用いてUICollectionViewCell内でcellのクリックイベントを捌きたいのですが、likeButton.rx.tapGesture()を用いてイベントを購読したところ、実際にタップした瞬間だけではなく、購読を開始した瞬間にもonNextが発火してしまいます。これを回避する方法があれば教えて頂きたいです。
またなぜこのような状態が起きてしまうのか教えていただきたいです。
class BarCollectionViewCell: UICollectionViewCell { @IBOutlet weak var likeButton: UIImageView! override func prepareForReuse() { bag = DisposeBag() } // collectionView.dequeueReusableCellした後にVC側から呼ばれます。 func setup(model) { updateVIew(model: model) subscribeEvents() } private func updateVIew(model: Model){ } private func subscribeEvents(){ likeButton.rx.tapGesture() .subscribe(onNext: { _ in print("tapGesture + OnNext") }, onError: { (err) in print("tapGesture + OnError") }, onCompleted: { print("tapGesture + OnCompleted") }, onDisposed: { print("tapGesture + OnDisposed") }).disposed(by: bag) } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。