0

This is my first app I am developing for my daughter studies who is in kindergarten and also my first question in stack overflow. Please excuse me if any format issues or if any irrelevance to the forum.

Requirements:

  1. I want a home page (home view) with drop down (or popuplist) with values like a. Addition b. Subtraction c. spellings etc.

and "start test" button on bottom

  1. Based on the drop down list options, I want to display the questions (around 10 questions per category) - "Test view"

It consists of 3 parts a. example (how to answer the question) b. question c. answer area (it can be text field(s) or radio button(s) based on question category in home page.

  1. Results view - After 10 questions are completed, it takes to results screens saying "congrats! your test is completed" (something like this). From there

This is what I have done so far

  1. First of all, I decided to use swift3 to create ios app and I created few png files (for questions) and kept them in assets folder for my use.
  2. I created 3 views and 3 view controllers (home view, test view and results view)
  3. each view has its own separate viewcontroller.swift files assigned
  4. I stored questions in 3 folders (additions, subtraction etc with 1.png, 2.png, 3.png etc)
  5. able to test the app for addition successfully as I placed sample images for additions on my "test" view. For additions, I am able to save questions in questions array and answers in answers array and able to complete the test for 10 questions and able to go to results page and display results. But I am stuck when extending this solution for more question categories like subtractions, spellings etc.

Now my question is

  1. If I want to handle subtraction and spelling, should I create another view for subtraction and another view for spelling? or is there any dynamic way to load the "test" view based on user drop down choice in home page ?

  2. Is there any properties file kind of concept in swift, where I can store the kind of values in drop down list and based on that "test" view will be loaded dynamically with sample questions and answer area (Note: answer area can be input text field or radio button based on question category)

  3. My current idea is to keep adding new view and new view controller when new category of questions are added but I felt this approach is not simple and robust as I need to add/modify the code every single time I add new category. I am trying to find a simple and robust way to handle this use case.

Any ideas would be greatly appreciated.

nrcr
  • 3
  • 3

1 Answers1

0

Question 1: You should use only one ViewController for all of your types of questions and create the views with the questions via code. To do so you have to add your images to the view. With an enum list you can identify which questions should be asked:

enum questionType {
    case addition
    case subtraction
    case spelling
}

In TestViewController you have

var type : questionType

Then if you instantinate your TestViewController you can set type and when the view is loading you can show your questions correspondingly. You can also check this var later to handle following processes.

Question 2: I'm not sure if I understand this question correctly. But I think you are looking for some technic for dropdown-lists? Then you can checkout the UIPickerView class. Here you can add your items and select one of them. You should find some tutorials to implement this in your app.

Question 3: You're right, creating new view controllers for each of the types is not a very simple solution and would confuse you sooner or later. And because the system is the same for each one it's better to have the code at one place so you only have to do the work one time and not 3 or more times and just add the code to handle new types of questions.

I hope I could help you :)

Community
  • 1
  • 1
Martin
  • 151
  • 10