title: UITableViewCell repeating UIImages
body: <p>This again is more of a math problem than anything else. I have 10 pictures in my resource bundle</p>
  
  <pre><code>sample_pic1.jpg
  sample_pic2.jpg
  sample_pic3.jpg
  ...
  sample_pic10.jpg
  </code></pre>
  
  <p>I have a table view with 100 rows. What I want to do is show the 10 sample pictures every 10 rows in cell image. Basically they keep repeating every 10 rows. The problem I have is I cannot think of a logic to repeat the images?</p>
  
  <p>This is what I have.</p>
  
  <p>NOTE: here indexPath.row keeps going from 0 through 99. So that is something I can use</p>
  
  <pre><code>// Customize the appearance of table view cells.
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
      //NSLog(@"Inside cellForRowAtIndexPath ... indexPath.row: %d", indexPath.row);
  
      static NSString *CellIdentifier = @"Cell";
  
      // Try to retrieve from the table view a now-unused cell with the given identifier.
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
      // If no cell is available, create a new one using the given identifier.
      if (cell == nil)
      {
          // Use the default cell style.
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
  
      }//nil-check
  
  
          int imageCounter = (indexPath.row+1);
  
          //ofcourse this logic doesn't work for rows 21 and up!
          if (imageCounter &gt; 10)
          {
              imageCounter = (indexPath.row+1) - 10;
          }
  
  
  
          NSLog(@"indexPath.row: %d ... imageCounter: %d ...", indexPath.row, imageCounter);
  
          NSMutableString *tmpImgStr = [NSMutableString stringWithFormat:@"sample_pic%d.jpg", imageCounter];
  
          UIImage *myimage = [UIImage imageNamed:tmpImgStr];
          cell.imageView.image = myimage;
  
  }
  </code></pre>