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

Coding IOS, error in code

I just can't figure this out....when i press the predict button, it just doesn't do anything....please help me figure it out!

2012-12-29 14:33:00.280 CrystalBall[1162:f803] -[NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x4894 2012-12-29 14:33:00.293 CrystalBall[1162:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x4894' *** First throw call stack: (0x14b1022 0xeb1cd6 0x14b2cbd 0x1417ed0 0x1417cb2 0x215c 0x14b2e99 0x1714e 0x170e6 0xbdade 0xbdfa7 0xbd266 0x3c3c0 0x3c5e6 0x22dc4 0x16634 0x139bef5 0x1485195 0x13e9ff2 0x13e88da 0x13e7d84 0x13e7c9b 0x139a7d8 0x139a88a 0x14626 0x1cbd 0x1c25) terminate called throwing an exception(lldb)

here is what my code looks like...

//
//  ViewController.m
//  CrystalBall
//
//  Created by Owner on 12/25/12.
//  Copyright (c) 2012 com.toptechnow. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize PredictionLabel;

- (void)viewDidLoad

{
[super viewDidLoad];
    self->predictionArray = [ [NSArray alloc] initWithObjects:@"It is certain",@"It is decidedly so" ,@"All signs say YES",
                                @"the stars are not aligned"
                                @"My reply is no",
                                @"It is doubtful",
                                @"Better not tell you now",
                                @"Concentrate and ask again",
                                @"Unable to answer now", nil];
}

- (void)viewDidUnload
{
    [self setPredictionLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    //Return Yes for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)ButtonPressed:(UIButton *)sender {

self->predictionArray = [self->predictionArray objectAtIndex:3];
}
@end

3 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

I'm surprised you are even able to compile because you have invalid sytax self->predictionArray. You should be using dot notation self.predictionArray.

Secondly, for the buttonPressed method you are getting an object and setting it to the predictionArray. You should be setting the text within your predictionLabel. Please see this video or the code associated in this video: http://teamtreehouse.com/library/ios-development/build-an-iphone-crystal-ball-app/getting-started/what-is-an-iboutlet

Deleted User

Amit, curious about why you thought it wouldn't compile.

Amit, I guess self->predictionArray is C/C++ way of calling functions/variables and as far as I know XCode doesn't arise any issue while compiling C/C++ syntax, but it may give trouble while running. I've experienced this while working with OpenCV library with IOS.