views:

29

answers:

0

Hi;

I'm using -setNeedsDisplayinRect to update only a part of my UIView. However, all of my drawing done previously to calling this method is erased.

Here is my code in the UIView subclass:

-(void)drawRect:(CGRect)rect{

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetRGBFillColor(context, r, g, b, 1);
    CGContextSetRGBStrokeColor(context, r, g, b, 1);

    CGRect arect = CGRectMake(x,y,1,1);


    CGContextFillRect(context, arect);


    NSLog(@"drawing");

}

and in the view controller:

-(void)drawView{

    drawingView = [[DrawingView alloc]init];

    x=10;
    y=10;
    r=0;
    g=0;
    b=0;

    [drawingView setNeedsDisplayInRect:CGRectMake(x, y, 1, 1)];

    x=20;
    y=20;
    r=0;
    g=0;
    b=0;


    [drawingView setNeedsDisplayInRect:CGRectMake(x, y, 1, 1)];
}

I end up with a screen where there is only one pixel at 20,20. Any help with this is so much appreciated. I am a beginner with XCode and am trying to complete a class project asap.