title: How to access a UIButton using a tag and change its image?
body: <p>I need to change the images on a matrix of UIButtons, and the only thing I know of to address the buttons, is the tag. But I can not find a way to actually us this identifier.
  The buttons are created programmatically during viewDidLoad.</p>
  
  <p>Here is the code for creating the buttons:</p>
  
  <pre><code>#define N_ROWS  4
  #define N_COLS  3
  
      int N_IMG = 0;
      for (int a = 0; a &lt; N_COLS; a++) {
          for (int j = 0; j &lt; N_ROWS; j++) {
  
  
              UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
              aButton.frame = CGRectMake(a * 65.0 + 25, j * 65.0 + 15, 10.0, 10.0);
              aButton.tag = j + a * N_ROWS + 1;
              [aButton setBackgroundColor:[UIColor redColor]];
  
              N_IMG = N_IMG++;
              [self.view addSubview:aButton]; 
              number_sorted =  1;
  
          }
      }
  </code></pre>
  
  <p>Here is the code for setting the image:</p>
  
  <pre><code>- (IBAction)set_image:(id)sender {
  
      #define N_ROWS  4
      #define N_COLS  3
  
          int N_IMG = 0;
          for (int a = 0; a &lt; N_COLS; a++) {
              for (int j = 0; j &lt; N_ROWS; j++) {
                  uibutton aButton.tag == (j + a * N_ROWS + 1) 
                  setImage:[UIImage imageNamed:[puzzles objectAtIndex:N_IMG]]
                              forState:UIControlStateNormal];
              N_IMG = N_IMG++;
  
              }
          }
      }
  </code></pre>
  
  <p>This is the code where the truble starts:
  uibutton aButton.tag == (j + a * N_ROWS + 1) </p>
  
  <p>Who can I set this up to work?</p>