title: tvOS UICollectionView not able to change focus when creating View programmatically
body: <p>I have a problem when creating a UICollectionView in Code as in comparison to creating the View in a Storyboard. In the programmatically created View, I am not able to change the focus, where as it works as intended in the storyboard version.</p>
  
  <p>This is how I create the UICollectionView</p>
  
  <pre><code>class ChannelGridViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.setup()
  }
  
  func setup() {
      let layout : UICollectionViewFlowLayout = UICollectionViewFlowLayout()
      layout.sectionInset = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50)
      layout.itemSize = CGSize(width: 350, height: 225)
  
      let grid = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
      grid.dataSource = self
      grid.delegate = self
      grid.userInteractionEnabled = true
      grid.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
      self.view.addSubview(grid)
  
  }
  </code></pre>
  
  <p>The setup method is the only additional method I added to the programmatically part.</p>
  
  <p>The rest of the methods are the following:</p>
  
  <pre><code>func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return 3
  }
  
  func numberOfSectionsInCollectionView(collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  func collectionView(collectionView: UICollectionView, canFocusItemAtIndexPath indexPath: NSIndexPath) -&gt; Bool {
      return true
  }
  
  func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath)
      cell.backgroundColor = .greenColor()
      cell.userInteractionEnabled = true
      cell.clipsToBounds = false
      return cell
  }
  
  func collectionView(collectionView: UICollectionView, shouldUpdateFocusInContext context: UICollectionViewFocusUpdateContext) -&gt; Bool {
      return true
  }
  
  override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
      if (context.nextFocusedView != nil) {
          coordinator.addCoordinatedAnimations({() -&gt; Void in
              context.nextFocusedView!.transform = CGAffineTransformMakeScale(1.05, 1.05)
              }, completion: { _ in })
      }
      if (context.previouslyFocusedView != nil) {
          coordinator.addCoordinatedAnimations({() -&gt; Void in
              context.previouslyFocusedView!.transform = CGAffineTransformMakeScale(1.0, 1.0)
              }, completion: { _ in })
      }
  }
  </code></pre>
  
  <p>I hope you guys might help me, as I couldn't find that problem after an extended time of googling and stackoverflowing. 99% of the tutorials are about storyboards. </p>
  
  <p>Thanks a lot,
  Alex</p>