0

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?

1
  • How does the input to your method look like? Why are your tiles called tile_1_1, tile_1_2 ... Where do they come from? If you name them that way, don't. Use an array like my answer suggests. Commented Mar 26, 2010 at 14:26

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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...
What exactly are you trying to do? Maybe a bit more context would help?
1

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);

2 Comments

a pointer to a pointer to a pointer ... Ie a List of a list of pointers to UIImages ...
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.