views:

107

answers:

3

I need to create an array of images in which, every time I tap, a new image gets placed at "view".

And at some particular duration of time, I need to clear that array of images so that all the images gets cleared from the view.

For example on button click I want to clear all the images which are on the view, through taps, should be clear at once.

+1  A: 

Do the 4 step dance (Declare, @property, @synthesize, [release]) And declare an NSArray.

NSArray* imagesArray;
@property (retain,nonatomic) NSArray *imagesArray;
@synthisize imagesArray;
//In your dealloc method relase the vairable***
imagesArray = [NSArray arrayWithObjects:[UIImage imageNamed:@""]];//Some initialization if you want :)

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/cl/NSMutableArray

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html

NSMutableArray defines an instance method - (void)addObject:(id)anObject to add things to your images array. You can then use - (void)removeObject:(id)anObject to remove the object. You would set these up by linking the buttons you want to have add and remove to respective methods that would perform these actions.

-(void)addImageBtnAction:(id)sender
-(void)removeImageBtnAction:(id)sender

Use these two methods (you can call them what ever you want) and when setting up the buttons (I do it all in code) set it's action to the corresponding Action event method you wrote. You can also link up the buttons through interface builder but I find that to be more trouble than it is worth and rather do it all programmicly so I can't show you how to use the IB way.

And forgot to add, adding the images to the view, have it get it's objects from the defined NSArray and refresh the view when adding or deleting.

Shadow
thanks mate, i will giv it a trythanks
shishir.bobby
A: 

How to create an image array and load into a view? - iPhone Dev ...

http://www.iphonedevsdk.com/forum/iphone-sdk-development/10364-how-create-image-array-load-into-view.html

Try This

ratty
A: 

what my condition right now is,

i hv 3 views.

on first view,i use tap to impose images on view1. simlarly wen after certain conditions i move from view 1 to view 2, same process occurs,(using taps to impose images)

i almost hv 50 small images of size 12X 12 on each views,

now wat i want to accomplish is, when i move back from view 2 to view 1, i should hv a clear view,i mean no images impose on views should be there...hope i m clear with my question....

quick reply is always appreciated.... regards shishir.bobby

shishir.bobby
i cant remove whole view,since it is needed,in every possible conditoin, is there any way to remove images imposed on view only be removed from the view......
shishir.bobby