代码之家  ›  专栏  ›  技术社区  ›  iosdevnyc

为什么uiimage的drawAtpoint在此代码中引发错误?

  •  0
  • iosdevnyc  · 技术社区  · 16 年前

    我正在我的iPhone AAP中创建自定义手机,我也在向其添加图像,但我继续在[图像绘制点: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];
    }
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Nikolai Ruhe    16 年前

    您不能将图像保留在设置器中( setImage: )正如错误消息所说,在您试图绘制它时,它已经消失了。