1

Im working on Survey app using ResearchKit and I need to change the values of the next question based on the previous response. Example:

Question 1: How many cars do you have?
- 1 Car
- 2 Cars
- 3 Cars
- 4 Cars
- xx Cars

Question 2: Which is your favorite car?
 - car number 1
 - car number 2
 - car number 3
 - car number 4
 - car number XX

The number of options of the question 2 will based on the value selected on Question 1.

Any idea how can I do that?

FelipeOliveira
  • 759
  • 8
  • 21

3 Answers3

1

I found out a solution, while it is not possible to create new steps after you presented the ViewController, It is possible to update answerFormat of a step using a new array

for(ORKQuestionStep* step in ((ORKOrderedTask*)self.task).steps) {
            if([step.answerFormat isKindOfClass:[ORKValuePickerAnswerFormat class]]) {
               step.answerFormat = [[ORKValuePickerAnswerFormat alloc] initWithTextChoices:arrayOfChoices];
            }
        }
FelipeOliveira
  • 759
  • 8
  • 21
1

Have a look at ORKNavigableOrderedTask. (See ORKTest for an usage example.)

Basically, you'd define individual steps for all the different options on the first question, and then conditionally navigate to the appropriate step based on its answer.

Ricardo Sanchez-Saez
  • 9,466
  • 8
  • 53
  • 92
0

You can also use:

func step(after step: ...) and
func step(before step: ...)

Using these you can create the steps themselves on-the-fly. However you also lose some other functionality and have to manage all the navigation yourself.

David Reich
  • 709
  • 6
  • 14