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
Ashley Jones
388 PointsCan't progress through IBAction & IBOutlet lectures: "terminate called throwing an exception"
There is a similar post with this question, but the answers for that one did not help me either. I am working on the "Buttons and IBAction" & "What is an IBOutlet" videos. I cannot get the simulation for either to work properly. It will not even display the predict button, and the console pops up with the message "terminate called throwing an exception". Here's what it shows: // // main.m // Crystal Ball // // Created by Belly on 8/11/13. // Copyright (c) 2013 Belly. All rights reserved. //
import <UIKit/UIKit.h>
import "AppDelegate.h"
int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
Here is my viewcontroller.h: // // ViewController.h // Crystal Ball // // Created by Belly on 8/11/13. // Copyright (c) 2013 Belly. All rights reserved. //
import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)buttonPressed:(id)sender; @property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
@end
And here is my viewController.m:
// // ViewController.m // Crystal Ball // // Created by Belly on 8/11/13. // Copyright (c) 2013 Belly. All rights reserved. //
import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. }
(void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
(IBAction)buttonPressed:(id)sender { self.predictionLabel.text = @"Definitely yes."; } @end
It looks identical to the previous post discussing this, and, as far as I can tell, identical to the video. As the previous post suggested, I made sure I used UILabel instead of UIButton, but it still did not work. I cannot figure out what I'm doing wrong. I'm still new at this, so I don't know what else to look for! Thanks in advance for your help.
1 Answer
Otto Wichmann
4,827 PointsI am new to ios development as well, but I will work with you trough this issue.
First I need to understand exactly what's not working.
Lets break it down. Your predict button doesn't display when you press play. Right? is that the first problem we have?
I dont understand why your ViewControler.h looks so different from mine: Here is my viewcontroler.h
//ViewController.h //CrystalBall
import < UIKit /UIKit . h> ///(I put the spaces in there so it wont make a bold IMPORT word)
@interface ViewController : UIViewController {
}
@property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
@property (strong, nonatomic) NSArray *predictionArray;
@property (strong, nonatomic) UIImageView *imageView;
-(void) makePrediction;
@end
//
So lets start there. Copy your ViewControler.h and lets make sure they look alike.
Cheers,
Otto
PD: I just realized something, that code that I have for my viewcontroler.h is "the final code" so yours may look a bit different. Still put it up here in the same organized manner that I posted mine so we can read it and find out where the issue is.