views:

62

answers:

2

Hi guys

I got a problem. I would add the same UIImageView at different places to my View. So I could make 10 UIImageViews with the same image but with other names. But i got ca. 50 UIImageViews...

I make my UIImageView with this code:

Code:

CGRect dragRect = CGRectMake(0.0f, 0.0f, 70.0, 70.0); 
dragRect.origin = CGPointMake(10, 300); 

UIImageView *image = [[UIImageView alloc] initWithFrame:dragRect];
[image setImage:[UIImage imageNamed:@"Apple.png"]];

[self.view addSubview:image;

Now i would like change my dracRect.origin point and make a new UIImageView with another name. I would do this with "for"

Is this possible?

Code:

int x;
for (x=0; x>=3; x=x+1) {

CGRect dragRect = CGRectMake(0.0f, 0.0f, 70.0, 70.0); 
dragRect.origin = CGPointMake(x*10, 300);  //x koordinate wird immer 10 grösser 

NSString *string1 = [[string1 alloc] initWithFormat:@"image%d",x]; //image1, image2, image3

UIImageView *string1 = [[UIImageView alloc] initWithFrame:dragRect];
[string1 setImage:[UIImage imageNamed:@"Apple.png"]];

[self.view addSubview:string1;

}

Thank you a lot for your help!

Franhu

A: 

did you try it? it should work. perhaps you have to release your UIImageView after you added the Subview, but i am not sure. i would bring the origin-calculation also in the CGRectMake but shouldn't be important. and don't you have to write: ...initWithFormat:@"image%i",x ? not sure, i am a xcode noob... :) i did something similar in an non-iphone project with matrices. but it's not possible to make matrices in the iphone sdk i believe.

Micko
First, thx for your comment. I tried it but i get an error:
uup my error is: conflicting types for 'string1'
your NSString and your UIImageView objects have the same name! i think independent from other errors this double naming can't work. try it with different names.
Micko
But this is what i want... my UIImageView should have the name of my string, because the string change every time..
why you don't give tags instead of names? i am even not sure what you mean with names and for what you want us this names.
Micko
A: 

Sorry i have to answer here!

I tried it with image%i and with image%d but i get an error: conflicting types of 'string1'

I dont even know if it's possible with my code...

thx for comment.