I'm new to Swift so please bear with me.
Firstly, let me explain my app layout:
I have a Text Field on the screen, with a Label and a button. I am asking the user 3 questions - these questions are displayed using the 'Label', and the next question appears each time the user presses the Next 'Button' (The questions are populated from an array).
One of the the questions needs to populate a Picker View (so the user can pick an option). One of the questions uses a normal keyboard. And the last question I need to use a Date Picker.
Is this possible to do? And if so, could you show me how to add it to my code below please?
let questions = ["What is your title?", "What is your full name?", "When were you born?"]
var currentQuestionIndex = 0
let placeholder = ["Title", "Full name", "Date of birth"]
var currentPlaceholderIndex = 0
@IBAction func nextButton(sender: AnyObject) {
textField.hidden = false
textField.placeholder = placeholder[currentPlaceholderIndex]
barImage.hidden = false
// Reset text field to have no text
textField.text = ""
questionLabel.text = questions[currentQuestionIndex]
// Displays the questions in array
if currentQuestionIndex < questions.count {
++currentQuestionIndex
// Displays the placeholder text in the textfield
if currentPlaceholderIndex < placeholder.count {
++currentPlaceholderIndex
}
buttonLabel.setTitle("Next", forState: UIControlState.Normal)
}
else {
//Add some logic here to run whenever the user has answered all the questions.
}
}
thanks for your help!
Nick
0 comments:
Post a Comment