Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jordan Garcia
2,393 PointsObjective-C loop through an array with button
I'm new to programming so take it easy, but I have an array of questions (NSArray *questions) in a class "Questions". I have a label (questionLabel) and a button (nextButton) on the View. When the button is pressed I want the label to loop through the array of questions. I made something similar here on Treehouse, but we used arc4random which doesn't look good because the same question can appear multiple times in a row before changing. I want to infinitely loop, in order, through the question array. I have copied my code for the button below.
The app runs but nothing happens when I press the button. I have honestly spent two weeks searching, learning, etc. and I have found nothing to help me figure this out. Any help is very much appreciated.
This code is in the ViewController.M file
-
(IBAction)nextButton {
NSArray *questions = [[NSArray alloc]init];
for (NSString *nextQuestion in questions) {
self.questionLabel.text = nextQuestion;}
}