title: iOS 6 Collection View Controller multiple dynamic cells
body: <p>I am only a week into Xcode, trying to learn something, so I can contribute to a project..</p>
  
  <p>So far I've been looking into tutorials and made something :) But I'm far from over. I hope someone will understand what I'll be asking..</p>
  
  <p>I'm making an app that will take data from a server, the data will include thumbnail images, images and text. Right now I have a collection view controller, with a cell that has 3 buttons (I find them easier to place around in the collection view cell), the button's background is a specific image (hard coded for now), and it takes you to a view controller, where all the content for that item are shown, nothing special :)</p>
  
  <p>But the layout (design) is hard for me to achieve. Basically (from my understanding) I need to have 4 collection view cells, with different positioned buttons. Now I have one collection view controller, with one collection view , containing one cell. </p>
  
  <pre><code>#import "CollectionViewController.h"
  #import "CollectionViewCell.h"
  #import "ImageDetailsViewController.h"
  #import "StoryItem.h"
  
  @interface CollectionViewController ()
  {
      NSArray *arrBigLeft;
      NSArray *arrSmallTopR;
      NSArray *arrSmallBotR;
  }
  
  @end
  
  @implementation CollectionViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          // Custom initialization
      }
      return self;
  }
  
  - (void)viewDidLoad
  {
  
  
      arrBigLeft = [[NSArray alloc]initWithObjects:@"imageicon0@2x.jpg", @"imageicon1@2x.jpg", @"imageicon2@2x.jpg", @"imageicon3@2x.jpg", nil];
  
      arrSmallTopR = [[NSArray alloc]initWithObjects:@"imageicon4@2x.jpg", @"imageicon5@2x.jpg", @"imageicon6@2x.jpg", @"imageicon7@2x.jpg", nil];
  
      arrSmallBotR = [[NSArray alloc]initWithObjects:@"imageicon8@2x.jpg", @"imageicon9@2x.jpg", @"imageicon0@2x.jpg", @"imageicon1@2x.jpg", nil];
  
      [super viewDidLoad];
  
      // Do any additional setup after loading the view.
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  
      if([segue.identifier isEqualToString:@"photoDetail1"]){
          CollectionViewCell *cell = (CollectionViewCell *)sender;
          NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
  
          ImageDetailsViewController *idvc = (ImageDetailsViewController *)[segue destinationViewController];
          idvc.img = [UIImage imageNamed:[arrBigLeft objectAtIndex:indexPath.item]];
  
      }
  
  
      if([segue.identifier isEqualToString:@"photoDetail2"]){
          CollectionViewCell *cell = (CollectionViewCell *)sender;
          NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
  
          ImageDetailsViewController *idvc = (ImageDetailsViewController *)[segue destinationViewController];
          idvc.img = [UIImage imageNamed:[arrSmallTopR objectAtIndex:indexPath.item]];
  
      }
  
  
      if([segue.identifier isEqualToString:@"photoDetail3"]){
          CollectionViewCell *cell = (CollectionViewCell *)sender;
          NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
                  ImageDetailsViewController *idvc = (ImageDetailsViewController *)[segue destinationViewController];
          idvc.img = [UIImage imageNamed:[arrSmallBotR objectAtIndex:indexPath.item]];
  
      }
  }
  
  - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
      return [arrBigLeft count];
  }
  
  
  
  // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  
      static NSString *identifier=@"Cell";
  
      CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
  
      [[cell button1]setBackgroundImage:[UIImage imageNamed:[arrBigLeft objectAtIndex:indexPath.item]] forState:UIControlStateNormal];
  
      [[cell button2]setBackgroundImage:[UIImage imageNamed:[arrSmallTopR objectAtIndex:indexPath.item]] forState:UIControlStateNormal];
  
      [[cell button3]setBackgroundImage:[UIImage imageNamed:[arrSmallBotR objectAtIndex:indexPath.item]] forState:UIControlStateNormal];
  
      return cell;
  }
  
  
  -(IBAction)returned:(UIStoryboardSegue *)segue {
  
  }
  
  
  
  @end
  </code></pre>
  
  <p>This doesn't work as I want it to yet, but at least I'm getting dynamically created cells. I'd like to be able to return multiple cells, with different arrays of items (images), and they all should load at the same time</p>
  
  <p><img src="https://i.stack.imgur.com/0hfGB.png" alt="screenshoot"></p>
  
  <p>here you can see only two cells, but the second one I added just to visualize what I'm trying to explain (4 different cells)
  The first cell (because of the number of images) repeats 4 times when I ran the app, if I was about to add the same images to the second cell, I would like to see them as in the screen shoot, and to continue to repeat in that order equal to the number of images (length of array)</p>
  
  <p>If you need more code, let me know.. thanks!</p>