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 trialAurelien Schlumberger
6,127 PointsmakePrediction method crashes my crystalBall app
I added the methods as explained in the video but my crystalBall crashes when I touch or shake the devices.
Is there a problem with my code?
AUDViewController.h:
...
- (void) makePrediction;
AUDViewController.m:
...
#pragma mark - Prediction
- (void) makePrediction {
self.predictionLabel.text = [self.crystalBall randomPredictions];
self.predictionLabel.textColor = [self.crystalBall randomColors];
}
...
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
[self makePrediction];
}
}
...
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self makePrediction];
}
1 Answer
Aurelien Schlumberger
6,127 PointsWell I figured it out and it was unrelated to the method makePrediction. It was crashing because I made a mistake when commenting out older code that I wanted to preserve
Bad comments:
// Removed because instead of using the button predict the random string, we use the touch screen event.
// - (IBAction)buttonPressed {
// self.predictionLabel.text = [self.crystalBall randomPrediction];
// self.predictionLabel.textColor = [self.crystalBall randomColor];
// }
Correct comments
// Removed because instead of using the button predict the random string, we use the touch screen event.
//- (IBAction)buttonPressed {
// self.predictionLabel.text = [self.crystalBall randomPrediction];
// self.predictionLabel.textColor = [self.crystalBall randomColor];
//}
I learn cool hotkey command to comment out chunks of code by pressing "command" + "/"