tags:

views:

183

answers:

1

I have a UIImageView that I created in the nib builder and was wondering how I would create multiple instances of this same ImageView ? Right now that imageview has code attached to it, so it can move around the screen randomly but I want more than one to spawn in the middle of the screen every few seconds.

A: 

Start off by sub-classing UIImageView - override the methods you want.

You'll probably have to set up the object in code rather than using Interface Builder. This is easier than it sounds as most of the properties can be called with the dot (.) syntax.

As for spawning every few seconds; have a look at NSTimer.

Answer to comment:

Try adding your newly created objects to an NSMutableArray then you can iterate through them and call the methods required.

rjstelling
Alright I got multiple instances to spawn but how do I link it up like I do with interface builder without actually using it ?something like... myImageView LINKED TO character1
so if I used this code to save all my image Views would I just call tempImage in my methods ?? Like for touchesMoved would this code only effect the image I'm currently touching or all the ones in the array... if([touch view] == tempImage ) { }
Here's the full code for the array. //initial array NSMutableArray *tempArray = [[NSMutableArray alloc]init]; for(int i=0 ; i<10 ; ++i) { UIImageView *tempImage = [[UIImageView alloc] initWithFrame:CGRectMake(120.0f, 120.0f, 20.0f, 60.0f)]; tempImage.image = [UIImage imageNamed:@"myimagePath"]; [tempArray addObject:tempImage]; [tempImage release]; } self.imageArray = tempArray; [tempArray release];