title: ios uiviewcontroller with collectionview subview not showing cells
body: <p>I have a uiviewcontroller with a subview which is a uicollection view. My view controller implements all of the collectionview delegates. For some reason some of the cells are black (when i scroll they appear , it seems randomly) My code is:</p>
  
  <pre><code>#import "NewGalleryViewController.h"
  
  @interface MyCell : UICollectionViewCell
  
  @property (nonatomic,strong) UIImageView *imageView;
  @end
  
  @implementation MyCell
  
  -(id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      NSLog(@"frame = %@\n", NSStringFromCGRect(frame));
      if (self)
      {
          self.imageView = [[UIImageView alloc] initWithFrame:frame];
          [self.contentView addSubview:self.imageView];
      }
      return self;
  }
  
  @end
  
  @interface NewGalleryViewController () &lt;UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout&gt;
  
  @property (nonatomic,strong) UICollectionView *collectionView;
  @end
  
  @implementation NewGalleryViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          // Custom initialization
      }
      return self;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
      UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
      [layout setItemSize:CGSizeMake(75, 75)];
  
      self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
      self.collectionView.delegate = self;
      self.collectionView.dataSource = self;
  
      [self.collectionView registerClass:[MyCell class] forCellWithReuseIdentifier:@"newcell"];
      [self.view addSubview:self.collectionView];
  }
  
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  {
      return 1;
  }
  - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  {
      return 100;
  }
  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newcell" forIndexPath:indexPath];
  
      cell.imageView.image = [UIImage imageNamed:@"114"];
      return cell;
  }
  
  
  
  -(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
  {
      NSLog(@"%ld",(long)indexPath.row);
  }
  
  - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      return CGSizeMake(75,75);
  }
  
  - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  {
      return UIEdgeInsetsMake(0, 0, 0, 0);
  }
  - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  {
      return 10;
  }
  - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  {
      return 0;
  }
  @end
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/okzNf.jpg" alt="Attaching a print screen"></p>
  
  <p><img src="https://i.stack.imgur.com/G1DnB.jpg" alt="Scrolling a bit down"></p>
  
  <p><img src="https://i.stack.imgur.com/mhM7p.jpg" alt="And print of all of the frames for the cells that are created (the seem reasonable for 4 cells in a row):"></p>