Textview value does not save to model properly using rxswift behaviorrelay


#1

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


#2

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

36%20AM

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.


#3

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