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
Logan Shire
2,539 PointsiOS App Dev Error. "terminate called throwing an exception"
Hi. I'm working through the iOS development tutorial and it seems that I have a newer version of Xcode than was used when the video was created (It says iPhone 6.0 simulator at the top.) I have followed the instructions exactly but when I try to run it I get the error in the title. It successfully built the simulation but when I clicked the predict button it crashed. This is what it brought up:
//
// main.m
// Crystal Ball
//
// Created by Logan Shire on 12/28/12.
//
//
#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 new header code:
//
// ViewController.h
// Crystal Ball
//
// Created by Logan Shire on 12/28/12.
//
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)buttonPressed:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
@end
And my new main code:
//
// ViewController.m
// Crystal Ball
//
// Created by Logan Shire on 12/28/12.
//
//
#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
I can't figure out what it's upset about now.
6 Answers
Your predictionLabelProperty is of type UIButton instead of the type UILabel.
Logan Shire
2,539 PointsOh. Ok. Thanks. You might want to update the video as it shows it using UIButton.
Which video?
Nick Pettit
Treehouse TeacherHi Logan,
I've notified Amit so that he can look into this.
Amit Bijlani
Treehouse Guest Teacher@Logan just checked the videos and looks like they are fine. Maybe you confused the IBAction with the IBOutlet. Given that they are new concepts it is understandable that it might take some time getting used to.
Cris Chirinos
1,451 PointsThis thread helped answer my question, but it does look like newer versions of Xcode do things a bit differently. I too was hung up on the "What is and IBOutlet?" video. In previous video when you connect the button to the ViewController.h (please pardon my description as I'm 1 day into learning this) I get the following:
(IBAction)buttonPressed:(UIButton *)sender {
The video shows:
(IBAction)buttonPressed:(id)sender {
So when you build upon the previous lessons, us newbies might not notice the change that needs to happen (UIButton to UILabel).
I'm liking this so far! Thanks Amit
Andy Brown
1,352 PointsI have the same problem, video shows a connection of Action with Type UIButton and the code added to the .h file is:
- (IBAction)buttonPressed:(id)sender;
On my version of xcode the same steps result in
- (IBAction)buttonPressed:(UIButton *)sender;
Still trying to figure out what I actually need...
- (IBAction)buttonPressed:(id)sender; or
- (IBAction)buttonPressed:(UIButton *)sender;
Amit Bijlani
Treehouse Guest TeacherThey both will work. id is a generic type to which you can assign an object that belongs to any class. Whereas, when you say UIButton then you are expecting the sender to be an object of type UIButton.