0
我在我的iphone aap中創建自定義單元格,並且我正在向其中添加一個圖像,但是我繼續在[image drawatpoint:p]處出現錯誤;爲什麼UIImage的drawAtPoint在這段代碼中拋出一個錯誤?
的錯誤狀態 *** - [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];
}
我加了圖片= [我保留]; 修復問題 – iosdevnyc 2009-10-30 19:02:15
現在您已經添加了[我保留];您還必須取消註釋[image release];在setImage中調用:避免內存泄漏。 – 2009-10-30 20:13:17
好聽起來不錯 – iosdevnyc 2009-11-01 12:52:03