0

I have an requirement to display list of questions and options, so that the user can select his own option for every question and be able to submit.

When submitting answers they should be validated and the result will be displayed to the user.

I am using tableview. In my table view I am adding custom cell (with multiple checkboxes ) in cellForRowIndexPath.

The problem is when I am scrolling down the tableview, the custom cell is restoring and selected options are assigned to another question.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Please explain it more, may be with screenshot – Himanshu Joshi Mar 06 '14 at 13:48
  • first off all: **add your code!** – vikingosegundo Mar 06 '14 at 13:57
  • 2
    Instead of a screenshot, please post the cellForRowAtIndexPath method. Please also take the time to use proper spelling and punctuation (and a meaningful title). –  Mar 06 '14 at 13:57
  • You should include your code so we are better able to find your problem. From the sound of your explanation, I'm guessing you have added custom views to your cell, and when you reuse the cell, they still have info from the previous use on them. If you're adding subviews to your custom cell, make sure they are not hanging around in your cell when it gets reused. – Marius Waldal Mar 06 '14 at 16:06

1 Answers1

0

You have to store all information of each cell in an NSArray. You should have a Model Class, wich holds the information for one cell.
So every time a checkbox gets changed, you have to write that information into your array.
In your function cellForRowAtIndexPath: you have to set the checkboxes with the values from your NSArray.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyCustomCell *currentCell = [self.tableView dequeueReusableCellWithIdentifier:@"MyCustomCell"];
    currentCell.textLabel.text = self.myArray[indexPath.row].description;
    currentCell.switch1.on = self.myArray[indexPath.row].firstAnswer;
    currentCell.switch2.on = self.myArray[indexPath.row].secondAnswer;

    return currentCell;
}
lootsch
  • 1,867
  • 13
  • 21