在我的网格类中,我有构造函数:
- (id) init
{
if ( self = [super init] )
{
isOccupied = NO;
gridImage = [[UIImage alloc] initWithContentsOfFile:@"grid.png"];
}
return self;
}
我将gridImage设置为属性。
在我的viewController中,我有:
UIImageView *temp = [[UIImageView alloc]initWithFrame:CGRectMake(10,10,200,200)];
[temp setImage: myGrid.gridImage];
[self.view addSubview: temp];
myGrid是Grid Class的一个实例... 但它没有显示?当我直接输入文件名时它可以工作,但不是当我使用属性访问时。有人可以帮忙吗?
我的网格标题:
@interface Grid : NSObject {
//Locations *locations[20][20];
BOOL isOccupied;
UIImage *gridImage;
//Locations *mergedlocations[20][20];
}
@property (retain) UIImage *gridImage
答案 0 :(得分:0)
可以使用retain吗?
以这种方式设置图像gridImage = [[UIImage imageNamed:@"grid.png"] retain];