iPhone UIImage Method crashes
I have this method in my Car.h class file:
@interface Car : NSObject {
NSString * name;
UIImage* image;
}
+ (id)withName:(NSString *)name withImage:(UIImage *)image;
@end
and my Car.m class file:
#import "Car.h"
@implementation Car
@synthesize name, image;
开发者_开发百科+ (id)withName:(NSString *)name withImage:(UIImage *)image {
Car *newCar = [[[self alloc] init] autorelease];
newCar.name = name;
newCar.image = image;
return newCar;
}
Now I have a MutableArray in a ViewController where I add new Car objects like this:
[myMutableArray addObject:[Car withName:name withImage:image];
But it crashes if image is anything but nil. I can return the name but it doesn't work with anything else but Strings. Could you help me please?
I'm assuming the @property omission is a typo (there's also a bracket missing from the last line of code), since I imagine that'd throw a compiler error. How are you getting image? Also, make sure your properties are set to retain, not just assign.
You don't appear to have @property declaration in your interface file
精彩评论