Friday, 15 August 2014

ios - Display questions from an array in order on a button press in swift -


I'm new to learning iOS swift, so if it's easy then apologies.

My application is the first page UILB (my question) UIIFFField (where users write their answer) UIButton (once input into the user's text field)

I have made one The array of 4 questions I am trying to code when the user presses UIButton, it will display the next question in the array, until the text field will be populated.

This is what I have done so far:

  @Iboutlet var textField: UITextField! @IBOutlet var QuestionsWell: UILBL! @Iboutlet var ButtelBel: UIButton! Ask the question = ["Where are you going?", "Do you know which city is?", "What are you doing there?", "When do you go?"] @ Ibitation Funk next button ( From: Any object) {textField Hidden = Wrong Textfield. Placeholder = "country" for var i = 0; I & lt; 5; I ++ {questionLabel.text = questions [0]} buttonBel .customized ("Next", forState: UIControlState.Normal)} Override Function ViewDidload () {super.viewDidLoad () // After loading any additional setup Generally, a nib / keyboard textfield.delegate = self buttonLabel.Citital ("Start", forState: UIControlState.Normal) questionLabel.text = "" // TextField hides textfield.hidden = true // text The image hides the background for the field BarImage.hidden = true}  

I am able to do this when the sub The user presses the 'Get Started' button, this button changes the text to say 'next', displays textfield and the first question in the array

but I am having trouble finding out that the user After answering once, how to go to the next question and press the next button.

Any help greatly appreciated. currentQuestionIndex to keep track of

nick

Add a property named where you are in the array and when you click on the button, you increase it:

var currentQuestionIndex = 0 @ ebbank funk nextButton (From: AnyObject) {textField.hidden = False textField.placeholder = "Country" QuestionLabel.text = questions [currentQuestionIndex] if currentQuestionIndex & lt; Question.count {++ currentQuestionIndex buttonLabel.setTitle ("Next", forState: UIControlState.Normal)} and {(Sender as UIButton) .userInteractionEnabled = false}}
< / Html>

No comments:

Post a Comment