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
Anand Altekar
1,617 PointsAnimation Crystall ball application
I'm getting a runtime error. I tried to debug the way Amit has explained in Debugging basics. When I went into the connections inspector of the View Controller, all my connections seem to be proper and the connection that Amit deletes in the video was never there. I'm still getting a runtime error. This is the exact error: CrystalBall[622:60b] -[UIView setAnimationImages:]: unrecognized selector sent to instance 0x9236160
Can anyone help?
Anand Altekar
1,617 Pointsby mistake I have posted my code as an answer, do check it. Thanks!
2 Answers
Anand Altekar
1,617 Pointsviewcontroller.h: @interface AAViewController : UIViewController @property (strong, nonatomic) IBOutlet UILabel *predictionLabel; @property (strong, nonatomic) AACrystalBall *crystalBall; @property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
viewcontroller.m
import "AAViewController.h"
import "AACrystalBall.h"
import <AudioToolbox/AudioToolbox.h>
@interface AAViewController ()
@end
@implementation AAViewController{ SystemSoundID soundEffect; }
//@end
//@implementation AAViewController
-
(void)viewDidLoad { [super viewDidLoad];
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"crystal_ball" ofType:@"mp3"]; NSURL *soundURL = [NSURL fileURLWithPath:soundPath]; AudioServicesCreateSystemSoundID(CFBridgingRetain(soundURL), &soundEffect);
self.crystalBall = [[AACrystalBall alloc] init]; self.backgroundImageView.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"CB00001"]..images till CB0060, nil]
self.backgroundImageView.animationDuration = 2.5f; self.backgroundImageView.animationRepeatCount = 1; }
- (void) didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
pragma mark - Prediction
- (void) makePrediction{ [self.backgroundImageView startAnimating]; 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"); }
Anand Altekar
1,617 PointsI added this line: self.backgroundImageView = [[UIImageView alloc] init]; above the backgroundImages.animationImages array since I thought i'm not allocating memory for the backgroundImageView object. Now the main bug doesn't appear, but now the problem is that the crystal ball won't animate. Any solutions?
Tillson G
4,171 PointsTillson G
4,171 PointsCould you show us some code?