【问题标题】:iPhone UIImage Method crashesiPhone UIImage 方法崩溃
【发布时间】: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,它就会崩溃。我可以返回名称,但它不适用于除字符串之外的任何其他内容。 你能帮帮我吗?

【问题讨论】:

    标签: iphone crash methods


    【解决方案1】:

    我假设@property 遗漏是一个错字(最后一行代码中还缺少一个括号),因为我想这会引发编译器错误。你怎么得到图像?此外,请确保您的属性设置为保留,而不仅仅是分配。

    【讨论】:

    • 你是对的,我做了@property(复制)而不是保留,非常感谢大家。
    【解决方案2】:

    您的接口文件中似乎没有@property 声明

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 2014-02-16
      相关资源
      最近更新 更多