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
Mihails Kerezins
671 PointsTo create an NSArray with UIColor objects...
- (void)viewDidLoad { [super viewDidLoad]; self.predictions = [[NSArray alloc] initWithObjects:@"It is certain", @"It is decidedly So", @"The stars are not aligned", @"My reply is no", @"It is doubtful", @"Better not to tell you now", @"Concentrate and ask again", @"Unable to answer now", nil]; self.colorArray = [[NSArray alloc] initWithObjects:[UIColor redColor], [UIColor blueColor], [UIColor yellowColor], [UIColor greenColor], nil]; }
(void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
-
(IBAction)buttonPressed {
int random = arc4random_uniform(self.predictions.count); self.predictionLabel.text = [self.predictions objectAtIndex:random]; self.predictionLabel = [self.colorArray ?????????]; }
What exactly I need to put where the question marks are??? Also what about the rest of the code? Is it right? I've added NSArray *colorArray in .h file.
2 Answers
Chad Goodyear
9,634 PointsLooking back at my old code, I used:
self.predictionLabel.textColor = [self.colorArray objectAtIndex:random2];
I'd created a second random number called 'random2', I guess you could reuse the original?
Hope that helps. I guess its the '.textcolor' bit your missing?
Mihails Kerezins
671 Points@Chad Goodyear Thank you so much! Got it right straight away!