Textview value does not save to model properly using rxswift behaviorrelay

I have this vc

that generates a cells same cells for each horizontal scroll

Im passing a model for each cell called Quiz

cell.configure(with: self.quizes[indexPath.row])

inside the Quiz model I have

public let questionBehavior: BehaviorRelay<String> = BehaviorRelay<String>(value: "")
public let answerBehavior: BehaviorRelay<String> = BehaviorRelay<String>(value: "")

which are about to have an input upon text change in the cell: QuizCreatorCell.swift

but then when I try to scroll next then go back the Im setting the textviews to

      self.questionTextView.text = quiz.questionBehavior.value
      self.answerTextView.text = quiz.answerBehavior.value

Im expecting the values will be different because Im passing a different model from the class

Because of this I think self.model = quiz. Take a look at this image:


Try to bind the values at cellForRow or don’t to the self.model = qiuz thingy in the configure func. And also this line

private let disposeBag = DisposeBag()

in your cell will result to duplicate subscriptions since your cell will always be reused. You should always set it to var and set a new instance in the prepareForReuse function.

1 Like

thanks, the DisposeBag() actually is the problem after changing it to var and making it nil on prepare for reuse it works fine now. thanks