2010-01-15 57 views
0

我有這個方法在我的Car.h類文件:iPhone的UIImage方法崩潰

@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; 
} 

現在我有一個視圖控制器,其中一個MutableArray我添加這樣的新車對象:

[myMutableArray addObject:[Car withName:name withImage:image]; 

但它崩潰,如果圖像是什麼,但零。我可以返回這個名字,但它不能與其他字符串一起工作。 你能幫我嗎?

回答

1

我假設@property遺漏是一個錯字(還有一個支架從代碼的最後一行丟失),因爲我想象這會拋出一個編譯器錯誤。你如何獲得形象?另外,請確保您的屬性設置爲保留,而不僅僅是分配。

+0

你說得對,我做了@property(copy)而不是保留,謝謝大家。 – scud 2010-01-15 02:19:12

0

你似乎沒有@property聲明在接口文件