Creating A Dynamic TableView with Custom Cells - ios

I'm looking to make a questionnaire app and trying to figure out the best way to implement this.
I'm familiar with TableViews and how to load content into them from an array but I'm having trouble figuring out a way to create a dynamic TableView that can expand or shrink depending on how many questions are asked per view.
My questions will be grouped so that each "page" will only display 1 group of question or questions at a time. This can vary from 1 question or more.
Every question will have 3 attributes of:
questionNumber, questionLabel, and questionType. These are all strings.
There are 7 question types which are:
yesNo, date, time, search, multipleSelection, textField and prompt.
Do I need to create custom cells for each and load them into the TableView or could I make separate Views that would then be loaded into a TableView?
I'm also going to use either a toolbar or a navbar to for the user to tap which would be next to go to the next group of questions or tap on previous which would get them back to the previous group of questions.
Any help to point me in the right direction would be appreciated. As of right now I would need to make 15 different view controllers and looking to possibly reduce the amount by just creating a TableView that would expand and shrink with questions and questionType. One page might only show a yes or no question while another page might have 2 or more questions each with a different questionType attached to them.

Related

save data in array coming from 2 different uitableviews in ios swift

Recently i am facing an issue in saving data of Uitableview inside Uitableview cell in ios swift
Senario
Questions asked in above pictures is one table view and this table view cell contain 1 label for question text and uitableview that show possible answers provided by admin and user is allowed to select one.i am enable to display data perfectly but facing an issue when trying to save answers of every question in one array.it always store the value of last questions answers.
Why are you using two different UITableView? Any specific reason? You can get data from different resources but there is no need to use two table views.
You should use a section header view to show the questions & sections rows as options(answer option).
You can dynamically add or delete the options(rows) from any section(question). Also, there will not be the above scenario if you implement it using this easy approach.
Let me know in case of any query.

ios swift3 quiz app - how many views should I create to handle 5-10 varieties of options

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:
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
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.
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
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.
I created 3 views and 3 view controllers (home view, test view and results view)
each view has its own separate viewcontroller.swift files assigned
I stored questions in 3 folders (additions, subtraction etc with 1.png, 2.png, 3.png etc)
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
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 ?
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)
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.
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 :)

Best practice to have multiple tableviews in a single view controller

This question maybe already asked in stackoverflow. But, I did not get any clear idea to my scenario.
I have a viewcontroller (Say, MyViewController).
I have a scrollview(Say, MyScrollView) and I have N number of views (Say MyView1, MyView2, ...) in it.
Those views can be scrolled horizontally. Refer the below image for more clarification.
This image was taken from here.
So, the red area is the scroll view that holds multiple views which are yellow color.
Scenario:
I want to call API's for each view, when the API calling and parsing data occurs, I need to show some loading activity indicator in the views. After successful parsing, I need to update corresponding view with UITableView.
Questions:
In my case, the number of views may vary from 3 to 6. Should I maintain 6 separate UITableViews and UIActivityIndicator's?
I tried with three pointers like left, middle & right to hold reference of tableview and activity indicator. But the problem is, before the first three pages are loading, if the user goes to the fourth view, this system will collapse with so many conditions.
Suggestions needed. Confused!!
I think you have to use UIPageViewController with UITableView. it will solve your problem.

Using a PList to integrate with buttons, not a table view

Right now I have a quiz that I made that has five seperate categories. There are certain stipulations that I need to keep in order for it to be used in its intended use. I started out with a simple switch statement to run the program because it made sense to me at the time and I thought I would be able to manipulate the quiz to run the way I want. Well, long story short I ran into one issue. My quiz runs like this:
Intro screen> Category selection screen where the user chooses one of the five categories > Question screen. But, the way that it runs after a user answers a question, it displays the correct answer and whether they were correct or incorrect and displays a button to go back to the selection screen. I could not figure out how to run through an entire category of questions and still maintain that correct/incorrect screen that displays each answer between each and every question. This is a learning tool, not a strict test and if they can't see the correct answer it is pointless.
So I started reading up on PLists. Trying to make this a more dynamic code has been confusing, but the only way I have figured out how to use PLists is using a table view, which changes up my GUI. Is there a way to still integrate a PList but maintain my same buttons and UILabel that will change with each question?
I.E here is an example how how it is now:
UILabel (This label hides until after a question is selected where it changes to Correct/Incorrect)
UILabel (changes with each different question)
Button1 (These four buttons changes with each respective answer)
UILabel (This label stays hidden until after a question is answered then will appear with the correct one)
Button2
Button3
Button4
All four buttons are set to hide after one is selected.
Is there a way pull data from the plist instead of using a table view to make the quiz. The spacing and the background image depends on using this type of interface over the tableview.
A side note question would be, would using Core Data be able to use this approach? Not a super important question because I think that Core Data from what it looks like is much too advanced for me. I do have a 2500 question quiz I will be making though pretty shortly and was thinking about looking it this.
Thanks for the help again guys! You have been very helpful. Is there way to get in contact with developers for more private help? I am currently deployed right now and it has made it very difficult finding any help while I am learning. So far I have read through Programming Objective C 6th edition and am about to start on the iOS development book I have and it would be nice to have someone to shoot a simple question to for a little clarity.
You probably want to create a singleton question controller (or at least instantiated a single instance with the selected category). Your other view controllers should probably be recreated each time you move to a new question / answer. The question controller manages knowledge of the selected category and which questions have been answered. It can also manage the score, question randomisation, etc.
The plist makes little difference really, only the question controller should know of it's existence (also the category controller perhaps).
2500 questions depends on the amount of text. Try it and see. The problem with a plist is that it is all loaded in memory at the same time. You could use a plist for the structure and other files for the text content of each question / answer.

Do I need to create a Storyboard for every Q&A in a quiz/trivia type of iOS applicaiton

Please forgive me for my n00bishness.
I am creating an app that asks several questions, and scores the result. Similar to something like an IQ test.
I would like to not have to create a storyboard for every question. I was wondering if I could create a storyboard for each question "type" and then populate that storyboard with questions from an array? For instance, while I may have 100 questions in the app, I want to only give the user 20 each time they run the app and I really only have three question "types":
Multiple Choice (one correct answer)
Multiple Selection (multiple selections allowed)
Yes or No
I would like to be able to create a standard screen for each of these types of questions and then populate the screen with text and scoring parameters from some sort of array.
If that is possible, I would probably like to create a large question set and then only feed in say 20 of 100 possible questions in a random fashion.
It seems like I also should create a "Question" class, and then spawn instances of that class for each question.
Is the the correct way to proceed?
You only need to create only one view controller for all the questions you are going to display, maintain an array of questions and make IBOutlets and IBActions for all the display components, Maintain current index of the question and write the logic for updating the question.
You can create one view controller in storyboard and then you can use different View for each category. Whenever any category is selected you can Hide/Show those corresponding views.
What you are thinking is the right approach.
You need to create just one storyboard which you'll be using to display the questions. The questions and the options being displayed on it would be dynamic.
Comment in case you are not able to find a tutorial for the same.

Resources