title: How to create a grid of UIButtons with dynamic values in iOS?
body: <p>I am trying to create a grid of UIButtons . The row and column values are dynamic.I know how to create a grid .However making it using dynamic values is the problem.</p>
  
  <pre><code> -(void)makeLayoutWithMinRow:(int)minRow maxRow:(int)maxRow minColumn:(int)minColumn maxColumn:(int)maxColumn {
  
      NSInteger intLeftMargin = 10; // horizontal offset from the edge of the screen
      NSInteger intTopMargin  = 10; // vertical offset from the edge of the screen
      NSInteger intYSpacing   = 30; // number of pixels between the button origins (vertically)
      NSInteger intXTile;
      NSInteger intYTile;
  
      NSInteger width;
  
      width = ((self.layoutView.frame.size.width-(maxColumn * 5))/maxColumn);
      for (int y = minRow; y &lt; maxRow; y++)
      {
          for (int x = minColumn; x &lt; maxColumn; x++)
          {
              intXTile = (x * width) + intLeftMargin;
              intYTile = (y * intYSpacing) + intTopMargin;
              UIButton *buttons[x][y] = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, width, 15)];
              //Here I get error : Variable-sized object may not be initialised.
  
              [self.layoutView addSubview:buttons[x][y]];
          }
      }
  }
  </code></pre>
  
  <p>I did try the option as suggested by Cornelius below to store the button in array.</p>
  
  <pre><code> sButton = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, width, 15)];
   [buttons addObject:sButton]; 
  </code></pre>
  
  <p>How to add these buttons to view in this case?</p>
  
  <pre><code>for (UIButton *obj in buttons) {
      [self.layoutView addSubview:obj];    //Doesn't work
  
  }
  </code></pre>