Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all articles
Browse latest Browse all 595

Option selected from one of the picker view duplicates in another picker view Swift

$
0
0

I've a survey with 8 questions and each question has a picker view with options loading from the server. This is in the UI Collection View. The survey works fine upto 5 questions but when we added more than 5, whatever the option we pick for the question 1 gets selected both for question1 and 6. same with question 2 and 3 which returns Index out of range error and I see only 5 answers instead of 8. Any help is appreciated.

Here is my code:

 override func collectionView(_ collectionView: UICollectionView,
                                 cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
                                                      for: indexPath) as! QuestionViewCell


        constructQuestionViewCell(cell, withQuestion: survey?.questions[indexPath.item])

        return cell
    }


private func constructQuestionViewCell(_ cell: QuestionViewCell, withQuestion question: SurveyQuestion? = nil) {
        cell.questionTitle.text = question?.title
        cell.questionTitle.numberOfLines = 0
        cell.questionTitle.sizeToFit()


if (question?.type == "number_list") {

let options = question?.values ?? ["", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]

let picker = CustomPickerView(frame: .zero, textView: cell.questionResponse, options: options)

cell.questionResponse.inputView = picker

 picker.reloadAllComponents()
       }

}

Viewing all articles
Browse latest Browse all 595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>