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

Mark McCuller
Mark McCuller
3,539 Points

Creating a Data Collection IOS7

in the Create an NSArray Property of Creating a Data Collection IOS7. I am stuck on last code challenge task 3 of 3, I other 2 are correct. Question #3 (Now it's time to display a quote from our 'quotes' array in the 'quoteLabel'. Assign the second item from the 'quotes' array to the text property of the 'quoteLabel'. Hint: use the 'objectAtIndex' method.) What am I doing wrong? My code is listed below:

Thank you for the help,

Mark

Task-1 (.h) Correct @property (strong, nonatomic) NSArray *quotes;

Task-2 (.m) Correct self.quotes = [[NSArray alloc] initWithObjects:@"Haters gonna hate", @"Life is simple", @"Winners never quit", @"quitters never win", nil];

Task-3 (.m) Wrong added code below from task-2.
self.quoteLabel.text = [self.quotes objectAtIndex:1];

7 Answers

Mark McCuller
Mark McCuller
3,539 Points

Cody,

In my task #3 I copied the line from the code challenge and the "o" is lower case for objectAtIndex. I copied your line of code and it comes back as wrong. I’m beginning to think it is a Web Browser issue in that is affecting the code challenges for passing. I am using Mozilla Firefox Version 24.0. If you passed the code challenge did you change anything else to pass? My code is the same as yours.

Thanks,

Mark

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

It's expecting the second quote which states "Life is simple, not easy". When you initialized the array you wrote: "Life is simple"

Amit is correct. I'm not sure why I thought it was the objectAtIndex, my fault.

Here is my code for the last two if you are still having issues:

Task 2: self.quotes = [[NSArray alloc] initWithObjects: @"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", nil];

Task 3: self.quoteLabel.text = [self.quotes objectAtIndex:1];

I came to the forums to post the exact same question. I am having the same exact problem except for Task-3 I have:

self.quoteLabel.text = [self.quotes ObjectAtIndex: 1];

Have you figured this out yet?

Mark McCuller
Mark McCuller
3,539 Points

Amit and Cody,

Thank you very much for your time, so I can know and understand what I am doing wrong in the code challenge. This keeps me going forward in learning programming at Treehouse. I see my mistake of forgetting to add the rest of the text in task #2. The code challenge passed the missing text for task #2 but would not let it pass in task #3. I really appreciate your help in this matter. I have a lot to learn but, I am enjoying the challenge of learning new skills everyday. Thank you for helping me as I begin to learn IOS programming, it is greatly appreciated.

Best Regards,

Mark McCuller

Emmanuel Darmon
Emmanuel Darmon
6,115 Points

I don't know what i am doing wrong in the task3:

import "THViewController.h"

@implementation THViewController

  • (void)viewDidLoad { [super viewDidLoad];

    // Add your code below! // Remember the array property is called 'quotes' // And the label property is called 'quoteLabel'

self.quotes= [[NSArray alloc]initWithObjects:@"Haters gonna hate", @"It is decidedly so", @"Life is simple, not easy", @"Winners never quit, quitters never win", Nil];

}

self.quoteLabel.text = [self.quotes ObjectAtIndex:1];

@end

Do i have to write:

  • (IBAction) buttonPressed {self.quoteLabel.text = [self.quotes ObjectAtIndex:1];}

And one last question: In the list, i wrote @"It is decidedly so", and it is not working if i am not adding this one... but it is a mistake, no? It is not asked in the question to write this one...

Thanks for your help!

@implementation THViewController

(void)viewDidLoad {

[super viewDidLoad];

//I am using the literal of an array @[] self.quotes=@[@"Haters gonna hate", @"It is decidedly so", @"Life is simple, not easy", @"Winners never quit, quitters never win"];

self.quoteLabel.text = [self.quotes ObjectAtIndex:1];

I hope it works!

@implementation THViewController

(void)viewDidLoad {

[super viewDidLoad];

//I am using the literal of an array @[] self.quotes=@[@"Haters gonna hate", @"It is decidedly so", @"Life is simple, not easy", @"Winners never quit, quitters never win"];

self.quoteLabel.text = [self.quotes ObjectAtIndex:1];

I hope it works!

@implementation THViewController

(void)viewDidLoad {

[super viewDidLoad];

//I am using the literal of an array @[] self.quotes=@[@"Haters gonna hate", @"It is decidedly so", @"Life is simple, not easy", @"Winners never quit, quitters never win"];

self.quoteLabel.text = [self.quotes ObjectAtIndex:1];

I hope it works!