IPhone-updating an array on button click
<p>I am new to IPhone development. </p>

<p>When I click on the button programmatically a new image in an IMAGEVIEW is displayed on the UIView. I want to store the images in some container and then use them later. </p>

<p>Here is my source code for creating images through UIGraphics.</p>

<pre><code>   if ([shape isEqualToString:@"Rectangle"])
    {

        UIGraphicsBeginImageContext(CGSizeMake(100.0, 100.0));
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 2.0);    
        CGRect main =CGRectMake(15.0, 15.0, 70.0, 30.0);
        CGContextFillRect(context, main);   

        CGRect topSeat1 = CGRectMake(15.0, 0.0, 15.0, 13.0);
        CGRect topSeat2 = CGRectMake(42.5, 0.0, 15.0, 13.0);
        CGRect topSeat3 = CGRectMake(70.0, 0.0, 15.0, 13.0);

        CGRect leftSeat = CGRectMake(0.0, 22.5, 13.0, 15.0);

        CGRect rightSeat = CGRectMake(87.0, 22.5, 13.0, 15.0);


        [[UIColor redColor]set];
        //UIRectFill(main);
        UIRectFill(topSeat1);
        UIRectFill(topSeat2);
        UIRectFill(topSeat3);
        UIRectFill(leftSeat);
        UIRectFill(rightSeat);
        UIRectFrame(main);

        [[UIColor blackColor]set];
        UIRectFrame(topSeat1);
        UIRectFrame(topSeat2);
        UIRectFrame(topSeat3);
        UIRectFrame(leftSeat);
        UIRectFrame(rightSeat);

        UIImage * image = [[UIImage alloc]init];
        image = UIGraphicsGetImageFromCurrentImageContext();

        myImage=[[UIImageView alloc]initWithImage:image];

        UIGraphicsEndImageContext();
        [self.view addSubview:myImage];
        [myImage setUserInteractionEnabled:YES];

        [arrayOfImages addObject:myImage];

    }
</code></pre>

<p>However the image is displayed but when I again click on the button, another images gets displayed but the older one on the UIView becomes static and I can't do anything to it. </p>

<p>I would prefer some code. </p>

<p>All I ask is:</p>

<ol>
<li><p>How to store them, so that on every button click the container gets populated or updated with UIImageViews.   </p></li>
<li><p>How to restore them later.</p></li>
</ol>
