views:

105

answers:

2

I want to do something like that:

         for (v=1;v=150;v++) {
          for (h=1; h=250;v++)   {
            tile_0%i_0%i.image = [UIImage imageWithData:tmp_content_of_tile];  //1st %i = v; 2nd %i = h
}
}

In the %i should be inserted the current value of "v" or "h"? Is it possible? How is it called?

Greets!

+1  A: 

I think what you want there is an array or a dictionary. See NSMutableArray and NSMutableDictionary. Even better, though, just use a plain old 2D array, as in the following:

// Allocate 2D array and fill with contents
UIImage*** imgs = (UIImage***) calloc(sizeof(UIImage**),150);
for (int v = 0; v < 150; v++){
   imgs[v] = (UIImage**) calloc(sizeof(UIImage*),250);
   for ( int u = 0; u < 250; u++ ){
      imgs[v][u] = // initialize entry
   }
}

// Using elements
UIImage* img = imgs[dim1_idx][dim2_idx];

// Freeing the array
for ( int v = 0; v < 150; v++ ){
    for (int u = 0; u < 250; u++ ){
       [ imgs[v][u] release ];
    }
    free(imgs[v]);
}
free(imgs);
Michael Aaron Safyan
What are the 3 *** for?
Markus S.
a pointer to a pointer to a pointer ... Ie a List of a list of pointers to UIImages ...
Goz
@Markus, in Objective-C, everything needs to be a pointer object, so the elements of the array are of type UIImage*. Then, since it is a 2D array, you need to add the ** to make it a 2D array.
Michael Aaron Safyan
+3  A: 

It is called an array, which in basic C/C++ would look like this:

Tile tile[150][250];
for (int v=0;v<150;v++) {
   for (int h=0; h<250;v++)   {
       tile[v][h].image = [UIImage imageWithData:tmp_content_of_tile];
   }
}

Also take a look at the syntax of the for loop.

Sebastian
+1 - funny and informative!
Eimantas
Problem is that sometimes the " 0 " before the v and h value mustn't be replaced and the underline must be there.I have to use a strict syntax for getting and setting the images in UIIMageViews because the tiles are generated by a other company whose use the tiles in a Flash Viewer.The Syntax of the tiles is like in my 1st post...
Markus S.
tile of type TILE?
Markus S.
What exactly are you trying to do? Maybe a bit more context would help?
Sebastian