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
Rodrigo Chousal
16,009 PointsCrystalBall App crashes...
I was watching the 'Intercepting Touch Events' video, and followed the instructions step by step. But for some reason, when I created a method for randomPrediction I don't get an error, I get this instead (after the app crashes): http://imgur.com/j2sITo6 This has happened to me before, when instead of displaying the normal return, I get this. My code is below... I'm so sorry for the mess...
Rodrigo Chousal
16,009 Points//(RCCrystalBall.m)
#import "RCCrystalBall.h"
@implementation RCCrystalBall
-(NSArray *) predictions {
if (_predictions == nil){
_predictions = [[NSArray alloc] initWithObjects:@"It is Certain", @"It is Decidedly so", @"All signs say YES", @"The stars are not aligned", @"The reply is no", @"It is doubtful", @"Better not tell you now", @"Concentrate and ask again", @"Unable to answer now", nil];
}
return _predictions;
}
-(NSString*) randomPrediction {
int random = arc4random_uniform(self.predictions.count);
return [self.predictions objectAtIndex:random];
}
@end
Rodrigo Chousal
16,009 Points//(RCViewController.h)
#import <UIKit/UIKit.h>
@class RCCrystalBall;
@interface RCViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
@property (strong, nonatomic) RCCrystalBall *crystalBall;
-(void) makePrediction;
@end
Rodrigo Chousal
16,009 Points//RCViewController.m
#import "RCViewController.h"
#import "RCCrystalBall.h"
@interface RCViewController ()
@end
@implementation RCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.crystalBall = [[RCCrystalBall alloc] init];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Motion Events
-(void) makePrediction {
self.predictionLabel.text = [self.crystalBall randomPrediction];
}
#pragma mark - Motion Events
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
self.predictionLabel.text = nil;
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if ( motion == UIEventSubtypeMotionShake ) {
[self makePrediction];
}
}
-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"motion cancelled");
}
#pragma mark - Touch Events
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.predictionLabel.text = nil;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self makePrediction];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches cancelled");
}
@end
1 Answer
Drew S
34,034 PointsHello Rodrigo,
The reason why your code stops executing is because you have a breakpoint set on line 59.
See where "59" is highlighted blue on the left.
Click on the number "59" to toggle the breakpoint, and then run your code.
Rodrigo Chousal
16,009 PointsThat simple huh? Thanks. By the way, what is a breakpoint?
Rodrigo Chousal
16,009 PointsRodrigo Chousal
16,009 Points