title: Create grid table view in iphone
body: <p>I want to make a table view in which i want to show some items or images ( 4 items in a row)For eg: If i have 7 images i want to show 4 in first row and 3 in next row and if i have 13 images then it should display like 4,4,4,1 in rows 1,2,3,4 respectively. I have achievd this but my problem is those images keep changing their position (shift from 1 to 3 row and vice versa) when i scroll the table view. Please tell me some way so that my images automatically adjust themselves 4 in a row and does not repeat if i scroll the table view.</p>
  
  <p>My code is:</p>
  
  <pre><code>(array has 7 image-datas stored in it) 
  
  
  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
      return 93;
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
      return [array count];
  }
  
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
  
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Avi"];
  
      for (UIView *view in cell.contentView.subviews) {
          [view removeFromSuperview];
      }
      if (cell == nil)
      {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Avi"] autorelease];
          cell.backgroundColor = [UIColor clearColor];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;
  
      }
  
  
      NSData *imageData;
  
  
          for(int i=0;i&lt;4;i++){
  
          imageData=[array objectAtIndex:indexpath.row];
  
          UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];
          Button.frame = CGRectMake(5+(i*77), 5, 77,85);
          [Button setBackgroundImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];
  
  
          [cell.contentView addSubview:Button];
  
  
      }
  
  return cell;
  </code></pre>