tags:

views:

15

answers:

0

How to save and retrive previous context from iphone ?

I am using the following code

int lineX=0;lineY=0;Xpos = 0;Ypos = 20;
CGContextRef context1;
context1 = UIGraphicsGetCurrentContext();
for(int i=0;i<[DataTable count];i++)
{
    NSString *strVal = [DataTable objectAtIndex:i];
    [strVal retain];
    NSLog(@"strval = %@",strVal);
    Ypos+=30;
    for(int draw=1;draw<5;draw++)
    {
        switch (draw) {
            case 1:
                string=strVal;
                Xpos=20;
                break;
            case 2:
                string=strVal;
                Xpos=120;
                break;
            case 3:
                string=strVal;
                Xpos=220;
                break;
            case 4:
                string=strVal;
                Xpos=320;
                break;
            default:
                break;
        }
        [self DrawTextView:context1 :0 :0 :0 :1 :Xpos :Ypos :string];
    }
    [self DrawLine:context1];

}



-(void)DrawLine:(CGContextRef)context
{
UIColor* color = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
lineY+=30;
CGContextSetStrokeColorWithColor(context, [color CGColor]);
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextMoveToPoint(context, lineX, lineY);
CGContextAddLineToPoint(context,MaxLinex,lineY);
CGContextStrokePath(context);
 }



-(void)DrawTextView:(CGContextRef)context :(float)R :(float)G :(float)B :(float)Al :(int)Xpos1 :(int)Ypos1 :(NSString *)s
{
NSLog(@"xpos = %d,ypos=%d",Xpos1,Ypos1);
strcpy(charProcedureName,[s cStringUsingEncoding:NSUTF8StringEncoding]);
CGContextSelectFont(context, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, R, G, B, Al);

CGAffineTransform xform = CGAffineTransformMake(
                                                1.0,  0.0,
                                                0.0, -1.0,
                                                0.0,  0.0);
CGContextSetTextMatrix(context, xform);

CGContextShowTextAtPoint(context, Xpos1, Ypos1, charProcedureName,  strlen(charProcedureName));
 }

This code works fine.When ever i draw with new data , the old data's are not displayed only the new data is displayed.How can i hold the old data in UIView.or tell me how to use the previous context as current context to draw data or how can i store and retrive the CGContextRef . Please i am really struggle with this .......... Plz help me..

Thanks in advance.......