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

iOS

Crystal Ball button does not show different predictions. In other words, it doesn't work. Help!

Can anybody tell me why this button does not display the correct object. ObjectAtIndex is set to 2. But it is still displaying 0 when I run the program and press the predict button. Any thoughts?

- (IBAction)buttonPressed {

    NSArray *predictions = [[NSArray alloc] initWithObjects:@"It is Certain", @"it is not certain", @"i dont know", nil];
    self.predictionLabel.text = [predictions objectAtIndex: 2];
}

@end

every thing here looks fine. is it displaying "It is Certain"?

Is your IBAction linked to a button in the Storyboard? And is there an @property in your header file for the predictionLabel?

1 Answer

It looks correct and working for me so thats odd. Try [predictions lastObject] to get the last object in your array.