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

iOS

Compiling issues due to animation code. Am I doing something wrong?

I have been having issues compiling my app since I added animations. I am not too sure what is going on, but there is a green highlight on the line stated above which is right about here I implement my animation and images. Please help. Am I doing something wrong? I think this is the only error I have so far.

import "THViewController.h"

import "THCrystalBall.h"

import <AudioToolbox/AudioToolbox.h>

@interface THViewController ()

@end

@implementation THViewController { SystemSoundID soundEffect; }

  • (void)viewDidLoad { [super viewDidLoad];

    NSString *soundPath = [[NSBundle mainBundle]pathForResource:@"crystal_ball" ofType:@"mp3"]; NSURL *soundURL = [NSURL fileURLWithPath:soundPath]; AudioServicesCreateSystemSoundID(CFBridgingRetain(soundURL), &soundEffect);

    self.crystalBall = [[THCrystalBall alloc] init]; self.backgroundImageView.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"CB00001"], [UIImage imageNamed:@"CB00003"], [UIImage imageNamed:@"CB00004"], [UIImage imageNamed:@"CB00005"], [UIImage imageNamed:@"CB00006"], [UIImage imageNamed:@"CB00007"], [UIImage imageNamed:@"CB00008"], [UIImage imageNamed:@"CB00009"], [UIImage imageNamed:@"CB00010"], [UIImage imageNamed:@"CB00011"], [UIImage imageNamed:@"CB00012"], [UIImage imageNamed:@"CB00013"], [UIImage imageNamed:@"CB00014"], [UIImage imageNamed:@"CB00015"], [UIImage imageNamed:@"CB00016"], [UIImage imageNamed:@"CB00017"], [UIImage imageNamed:@"CB00018"], [UIImage imageNamed:@"CB00019"], [UIImage imageNamed:@"CB00020"], [UIImage imageNamed:@"CB00021"], [UIImage imageNamed:@"CB00022"], [UIImage imageNamed:@"CB00023"], [UIImage imageNamed:@"CB00024"], [UIImage imageNamed:@"CB00025"], [UIImage imageNamed:@"CB00026"], [UIImage imageNamed:@"CB00027"], [UIImage imageNamed:@"CB00028"], [UIImage imageNamed:@"CB00029"], [UIImage imageNamed:@"CB00030"], [UIImage imageNamed:@"CB00031"], [UIImage imageNamed:@"CB00032"], [UIImage imageNamed:@"CB00033"], [UIImage imageNamed:@"CB00034"], [UIImage imageNamed:@"CB00035"], [UIImage imageNamed:@"CB00036"], [UIImage imageNamed:@"CB00037"], [UIImage imageNamed:@"CB00038"], [UIImage imageNamed:@"CB00039"], [UIImage imageNamed:@"CB00040"], [UIImage imageNamed:@"CB00041"], [UIImage imageNamed:@"CB00042"], [UIImage imageNamed:@"CB00043"], [UIImage imageNamed:@"CB00044"], [UIImage imageNamed:@"CB00045"], [UIImage imageNamed:@"CB00046"], [UIImage imageNamed:@"CB00047"], [UIImage imageNamed:@"CB00048"], [UIImage imageNamed:@"CB00049"], [UIImage imageNamed:@"CB00050"], [UIImage imageNamed:@"CB00051"], [UIImage imageNamed:@"CB00052"], [UIImage imageNamed:@"CB00053"], [UIImage imageNamed:@"CB00054"], [UIImage imageNamed:@"CB00055"], [UIImage imageNamed:@"CB00056"], [UIImage imageNamed:@"CB00057"], [UIImage imageNamed:@"CB00058"], [UIImage imageNamed:@"CB00059"], [UIImage imageNamed:@"CB00060"],nil]; self.backgroundImageView.animationDuration = 2.5f; self.backgroundImageView.animationRepeatCount = 1;

    UIImage *backgroundImage = [UIImage imageNamed:@"background"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:backgroundImage]; [self.view insertSubview:imageView atIndex:0]; }

  • (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]; AudioServicesPlaySystemSound(soundEffect);

[UIView animateWithDuration:6.0 animations:^{
    self.predictionLabel.alpha = 1.0f;
}];

}

pragma mark - Motion Events

-(void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ self.predictionLabel.text = nil; self.predictionLabel.alpha = 0.0f; }

-(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; self.predictionLabel.alpha = 0.0f; }

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self makePrediction];

}

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touches cancelled"); }

@end

Here is what it says in the debugging console

2014-09-04 21:36:26.854 Crystal Ball[1438:60b] -[UIView setAnimationImages:]: unrecognized selector sent to instance 0x178175a80 2014-09-04 21:36:26.856 Crystal Ball[1438:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setAnimationImages:]: unrecognized selector sent to instance 0x178175a80' *** First throw call stack: (0x18d93309c 0x1998b1d78 0x18d937d14 0x18d935a7c 0x18d8554ac 0x1000b17e4 0x1908082c0 0x190808044 0x19080f7dc 0x19080cab0 0x19088088c 0x19087d1f0 0x1908769a0 0x190809530 0x190808720 0x1908760b0 0x193259128 0x193258c54 0x18d8f2fc8 0x18d8f2f28 0x18d8f114c 0x18d831b38 0x1908752d4 0x1908700e8 0x1000b2848 0x199e9baa0) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

2 Answers

Hey Irwin,

Not sure if this is the cause of your issue, but you are still setting the background image programatically with UIImage. In the example this is removed and set through the Interface Builder. Amit does state that not doing this will cause issues with the animation.

(Don't think it would cause an issue but I also noticed you are missing image CB00002 in your animation array).

Let me know if removing UIImage and setting the background via IB worked.

Hello!

Thank you for responding! I took a look and you were right, there were a ton of things that were fixed. But I took a look again and now it shows this on my main file.

return UIApplicationMain(argc, argv, nil, NSStringFromClass([THAppDelegate class]));

I'm aware that Amit took care of this but I'm not having the same issued depicted on the video. Could this still have something to do with my View Controller? Specifically, it says thread 1 signal SIGABRT

Hey Irwin,

From what I could see everything else looked ok. Towards the end of the course Amit discusses the debugger and using Exception breakpoints to help troubleshoot any issues. You can also use a slider to expand the threads at the time of execution to try to pin point what is causing the issue.