我正在iphone中创建自定义单元格,我也在添加图像,但我仍然在[image drawatpoint:p]中出现错误;
错误状态 *** - [UIImage drawAtPoint:]:发送到解除分配的实例0x45cb1f0的消息
我的代码是
-(void)setImage:(UIImage *)i
{
//[image release];
image = i;
[self setNeedsDisplay];
}
- (void)setNeedsDisplay
{
[super setNeedsDisplay];
[contentView setNeedsDisplay];
}
- (void)drawContentView:(CGRect)r
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *backgroundColor = [UIColor yellowColor];
UIColor *textColor = [UIColor blackColor];
if(self.selected)
{
backgroundColor = [UIColor clearColor];
textColor = [UIColor whiteColor];
}
[backgroundColor set];
CGContextFillRect(context, r);
CGPoint p;
p.x = 3;
p.y = 3;
[textColor set];
UIImage *image2 = image;
[image2 drawAtPoint:p];
p.x += 70; // space between words
[text2 drawAtPoint:p withFont:firstTextFont];
//[image release];
}
答案 0 :(得分:1)
您不会在您的设置器中保留图像(setImage:
)。正如错误消息所示,它在您尝试绘制它时已经消失。