Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fox10078

macrumors 6502
Original poster
Nov 6, 2009
467
86
Ok so I'm creating my first app trying to create a simple animation, I thought I've done it all right I get no errors or anything of the sort But the app crashes in the simulator and on the device.

Heres my code in the .h
Code:
@interface BBQViewController : UIViewController {
	UIImageView *grill;

}

@end
And the .m

Code:
- (void)viewDidLoad {

	[super viewDidLoad];
	
	grill.animationImages = [NSArray arrayWithObjects:
							 [UIImage imageNamed:@"bbq1.png"],
							 [UIImage imageNamed:@"bbq2.png"],
							 [UIImage imageNamed:@"bbq3.png"],nil];
	grill.animationDuration = 2.00;
	grill.animationRepeatCount = 0;
	[grill startAnimating];
	[self.view addSubview:grill];
			
	
}

Any help would be greatly appreciated.
 
The Debugger shows _kill everytime I run it, I hope this is what you meant if not ill continue to search.
 
This is the full line. That it highlights when I run in debugger.
0x9160f132 <+0010> jae 0x9160f142 <__kill+26>
 
Code:
[Session started at 2010-06-15 15:08:16 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May  5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 34179.
2010-06-15 15:08:18.796 BBQ[34179:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x5c094f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
*** Call stack at first throw:
(
	0   CoreFoundation                      0x0238c919 __exceptionPreprocess + 185
	1   libobjc.A.dylib                     0x024da5de objc_exception_throw + 47
	2   CoreFoundation                      0x0238c851 -[NSException raise] + 17
	3   Foundation                          0x00028c2b _NSSetUsingKeyValueSetter + 135
	4   Foundation                          0x00028b99 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
	5   UIKit                               0x004a2d0a -[UIRuntimeOutletConnection connect] + 112
	6   CoreFoundation                      0x02302b6f -[NSArray makeObjectsPerformSelector:] + 239
	7   UIKit                               0x004a1721 -[UINib instantiateWithOwner:options:] + 1041
	8   UIKit                               0x004a34b5 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
	9   UIKit                               0x002b29bb -[UIApplication _loadMainNibFile] + 172
	10  UIKit                               0x002b390d -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 198
	11  UIKit                               0x002bd452 -[UIApplication handleEvent:withNewEvent:] + 1958
	12  UIKit                               0x002b6074 -[UIApplication sendEvent:] + 71
	13  UIKit                               0x002baac4 _UIApplicationHandleEvent + 7495
	14  GraphicsServices                    0x02bf2afa PurpleEventCallback + 1578
	15  CoreFoundation                      0x0236ddc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
	16  CoreFoundation                      0x022ce737 __CFRunLoopDoSource1 + 215
	17  CoreFoundation                      0x022cb9c3 __CFRunLoopRun + 979
	18  CoreFoundation                      0x022cb280 CFRunLoopRunSpecific + 208
	19  CoreFoundation                      0x022cb1a1 CFRunLoopRunInMode + 97
	20  UIKit                               0x002b3226 -[UIApplication _run] + 625
	21  UIKit                               0x002beb58 UIApplicationMain + 1160
	22  BBQ                                 0x000021d8 main + 102
	23  BBQ                                 0x00002169 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
(gdb)
I Apologize, I haven't used Xcode before.
 
So the exception is clearly at the top: "NSUnknownKeyException', reason: '[<UIApplication 0x5c094f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.".

It seems to crash as it's trying to connect the outlets in a nib/xib. What, exactly, is in the XIB file?
 
I've no idea as I don't know what your intentions are. Without one I don't see how you have connected the variable grill to anything in the xib file so it'll never be initialised to anything and be nil.
 
Well Im trying to cycle through the Images to create a look of a flame. I added the IBoutlet and connect the UIImageView to grill but still receiving the same message in debugger.
 
Well Im trying to cycle through the Images to create a look of a flame. I added the IBoutlet and connect the UIImageView to grill but still receiving the same message in debugger.

This may help you:
http://www.vellios.com/2010/05/31/code-for-animated-sprites/

You can then simply do the following:

Code:
Sprite *flame = [SpriteHelpers setupAnimatedSprite:self.view numFrames:3 withFilePrefix:@"bbq" withDuration:0.4 ofType:@"png" withValue:0];

Change "withDuration:0.4" to the animation duration.
Sprite inherits from UIImageView so anything you can do with UIImageView you can do with Sprite.
 
Thanks a lot, That last snippet of code you posted, Where would i Implement that?
 
Thanks a lot, That last snippet of code you posted, Where would i Implement that?

That code will programatically create an animated UIImageView (or in this case, Sprite). You could put it in viewDidLoad.

Then you can use [flame setCenter:CGPointMake(x,y)]; to set the position of the Sprite.
 
Ok, So if I'm understanding that line, it goes out and finds the files with the bbq prefix that are png format?
 
I went through your tutorial and I got these errors

This was in the spritehelpers.m and .h
error: expected ')' before 'Sprite'

This was in the spritehelpers.m
error: expected ':' before ']' token



Any ideas?
 
I went through your tutorial and I got these errors

This was in the spritehelpers.m and .h
error: expected ')' before 'Sprite'

This was in the spritehelpers.m
error: expected ':' before ']' token

Any ideas?

Not enough info there for me to help you. Post where those errors are showing up at in the actual code.
 
Here are the errors for the Spritehelpers.m
Code:
#import "SpriteHelpers.h"


@implementation SpriteHelpers

[COLOR="Red"]+ (Sprite *) setupAnimatedSprite:(id)sender numFrames:(NSInteger)frames withFilePrefix:(NSString *)ext withValue:(NSInteger)val withCenter:(CGPoint *)center {  [expected ')' before 'Sprite'][/COLOR]
	NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:0];

	for (int i = 1; i < frames +1; i++) {
[COLOR="Red"]		NSString *spritePath = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%@%d", filePrefix, i] ofType:ext]; ['filePrefix' undeclared][/COLOR]
		UIImage *sprite = [[UIImage alloc] initWithContentsOfFile: spritePath];
		
		[spriteArray addObject:sprite];
	        [sprite release];



	}
	for (int i = frames - 1; i > 1; i--) {
		NSString *spritePath = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%@%d", filePrefix, i] ofType:ext];
		UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:spritePath];
		
		[spriteArray addObject:sprite];
		[COLOR="Red"][sprite.release]; [expected ':' before ']' token][/COLOR]
		
	}

Heres the .h Errors

Code:
@interface SpriteHelpers : NSObject { }

[COLOR="Red"]+ (Sprite *)setupAnimatedSprite:(id)sender numFrames:(NSInteger)frames withFilePrefix:(NSString *)filePrefix withDuration:(CGFloat)duration ofType:(NSString *)ext withValue:(NSInteger)val withCenter:(CGPoint *)center; [expected ')' before 'Sprite']
[/COLOR]

@end
 
Here are the errors for the Spritehelpers.m
Code:
#import "SpriteHelpers.h"


@implementation SpriteHelpers

[COLOR="Red"]+ (Sprite *) setupAnimatedSprite:(id)sender numFrames:(NSInteger)frames withFilePrefix:(NSString *)ext withValue:(NSInteger)val withCenter:(CGPoint *)center {  [expected ')' before 'Sprite'][/COLOR]
	NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:0];

	for (int i = 1; i < frames +1; i++) {
[COLOR="Red"]		NSString *spritePath = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%@%d", filePrefix, i] ofType:ext]; ['filePrefix' undeclared][/COLOR]
		UIImage *sprite = [[UIImage alloc] initWithContentsOfFile: spritePath];
		
		[spriteArray addObject:sprite];
	        [sprite release];



	}
	for (int i = frames - 1; i > 1; i--) {
		NSString *spritePath = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%@%d", filePrefix, i] ofType:ext];
		UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:spritePath];
		
		[spriteArray addObject:sprite];
		[COLOR="Red"][sprite.release]; [expected ':' before ']' token][/COLOR]
		
	}

Heres the .h Errors

Code:
@interface SpriteHelpers : NSObject { }

[COLOR="Red"]+ (Sprite *)setupAnimatedSprite:(id)sender numFrames:(NSInteger)frames withFilePrefix:(NSString *)filePrefix withDuration:(CGFloat)duration ofType:(NSString *)ext withValue:(NSInteger)val withCenter:(CGPoint *)center; [expected ')' before 'Sprite']
[/COLOR]

@end
  • Did you remember to import Sprite.h into SpriteHelpers.h?
  • You'll need to declare filePrefix
  • sprite has no release property; you want to be calling the release method
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.