【发布时间】:2010-01-15 01:41:15
【问题描述】:
我的 Car.h 类文件中有这个方法:
@interface Car : NSObject {
NSString * name;
UIImage* image;
}
+ (id)withName:(NSString *)name withImage:(UIImage *)image;
@end
还有我的 Car.m 类文件:
#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;
}
现在我在 ViewController 中有一个 MutableArray,我可以在其中添加新的 Car 对象,如下所示:
[myMutableArray addObject:[Car withName:name withImage:image];
但是如果 image 不是 nil,它就会崩溃。我可以返回名称,但它不适用于除字符串之外的任何其他内容。 你能帮帮我吗?
【问题讨论】: