title: UICollectionView loading with noticeable lag the very first time
body: <p>I have a simple application that contains an in-app settings <code>Table View Controller</code>. When the user selects the "App Themes" cell, it <code>segues</code> (push) over to a <code>UICollectionView</code> embedded in a <code>UIViewController</code>. </p>
  
  <p>This is 12 Cells in a 3x4 fashion where each cell has an image, a label and a checkmark image if that theme has been selected. </p>
  
  <p>The cells are loaded dynamically within the class here but I'm noticing some major delay when segueing over to this <code>UICollectionView</code> for the first time. Every subsequent time, it works fine but on an iPhone 5s, there's some extreme noticeable lag and I'm fairly new to iOS Development and I have a feeling it's something to do with how the views get created the first time, etc, but I'm not sure. </p>
  
  <p>In my <code>viewDidLoad</code>, I have:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      self.title = @"Themes";
      self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
    [super viewDidLoad];
      self.cView.dataSource = self;
      self.cView.delegate = self;
  
  
      self.themeLabels = [[NSArray alloc] initWithObjects:@"Original", @"Peacock", @"Mystical", @"Zebra", @"Simplicity", @"Rainbow", @"Prosperity", @"Leopard", @"Hypnotic", @"Dunes", @"Twirl", @"Oceanic", nil];
  
      self.themeImages = @[[UIImage imageNamed:@"Newiphonebackground.png"], [UIImage imageNamed:@"peacock.png"], [UIImage imageNamed:@"Purplepink.png"], [UIImage imageNamed:@"PinkZebra.png"], [UIImage imageNamed:@"Greenish.png"], [UIImage imageNamed:@"MarblePrint.png"], [UIImage imageNamed:@"Prosperity.png"], [UIImage imageNamed:@"leopard.png"], [UIImage imageNamed:@"CircleEffect.png"], [UIImage imageNamed:@"Orange3.png"], [UIImage imageNamed:@"ReddishBlack.png"], [UIImage imageNamed:@"bluey.png"]];
  
      [self changeAppThemes];
  
  }
  </code></pre>
  
  <p>The changeAppThemes method is essentially cycling through the NSUserDefaults and seeing which theme to apply. </p>
  
  <pre><code>- (void)changeAppThemes
  {
      self.selectedTheme = [[NSUserDefaults standardUserDefaults] objectForKey:@"Theme"];
  
      if ([self.selectedTheme isEqualToString:@"Mystical"])
      {
          self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Purplepink.png"]];
          UIImage *navBackgroundImage = [[UIImage imageNamed: @"Purplepinknav"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
          [self.navigationController.navigationBar setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
  
          UIImage *tabBackground = [[UIImage imageNamed:@"SolidPurple.png"]
                                    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
          [self.tabBarController.tabBar setBackgroundImage:tabBackground];
      }
  
  etc
  </code></pre>
  
  <p>The <code>viewWillAppear</code> is:</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated
  {
      [super viewWillAppear:animated];
      [self changeAppThemes];
  
      self.selectedThemeString = [[NSUserDefaults standardUserDefaults] objectForKey:@"Selection"];
  
      if ([self.selectedThemeString isEqualToString:@"Original"])
      {
          self.checkedIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
      }
  
      else if ([self.selectedThemeString isEqualToString:@"Oceanic"])
      {
          self.checkedIndexPath = [NSIndexPath indexPathForRow:11 inSection:0];
      }
  
      [self.cView reloadData];
  
  }
  </code></pre>
  
  <p>The <code>viewWillAppear</code> before today only had the call to the <code>changeAppThemes</code> method without the other code but it was still very unresponsive when segueing to the <code>UICollectionView</code> for the first time. </p>
  
  <p>The <code>cellForItemAtIndexPath</code> is:</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
  
      ThemeCell *themeCell = (ThemeCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Theme Cell" forIndexPath:indexPath];
  
      NSString *cellData = [self.themeLabels objectAtIndex:indexPath.row];
  
      themeCell.cellLabel.text = cellData;
      themeCell.cellImages.image = self.themeImages[indexPath.row];
      UIImageView *dot = [[UIImageView alloc]initWithFrame:CGRectMake(5, 0, 1, 2)];
      dot.image=[UIImage imageNamed:@"check-white-hi.png"];
  
      if([self.checkedIndexPath isEqual:indexPath])
      {
          NSLog(@"Loaded");
          themeCell.backgroundView = dot;
          [themeCell addSubview:dot];
  
      }
      else
      {
          NSLog(@"Not Loaded");
  
          themeCell.backgroundView = nil;
      }
  </code></pre>
  
  <p>Should I be changing where I place the call to the <code>changeAppThemes</code>? I have removed the call from the <code>viewWillAppear</code> and left it in the <code>viewDidLoad</code> and also vice versa and in both cases, the responsiveness was really bad when opening up the <code>UICollectionView</code> for the first time. </p>
  
  <p>Any thoughts would be really appreciated. </p>