title: How do I manually focus a certain cell in a UICollectionView only on first load?
body: <p>I'm pretty new to swift and I'm trying to make a certain cell focused in a horizontal scrollable UICollectionView when I load into a page for the first time. The page fits about 4 cells across horizontally. Right now I'm trying to do:</p>
  
  <pre><code>collectionView.scrollToItem(IndexPath(row: 3, section: 0), at: .left, animated: true)
  </code></pre>
  
  <p>in <code>viewDidLoad</code> in order to focus the fourth cell upon clicking into the page. If there are at least 7 items in the collection view, this will work correctly since the fourth cell will be on the left, but if not, it will end up focusing on one of the first 3 items, since you can't scroll past the fourth item enough so that the fourth item is on the left. How do I make sure the fourth item is not only scrolled to but also explicitly focused?</p>
  
  <p>I tried using <code>func indexPathForPreferredFocusedView(in collectionView: UICollectionView) -&gt; IndexPath?</code> as well, which seems to make it work, but the problem is I don't want the fourth item to be focused all the time, only on the first load of this specific page. I also use this collection view in other places in the app where I don't want this manual focus.</p>
  
  <p>I tried to override <code>preferredFocusEnvironments</code> with the cell at that index path but for some reason, <code>collectionView.cellForItem(at: IndexPath(row: 3, section: 0))</code> always returns nil.</p>
  
  <p>It seems like focusing the index path is the only thing that seems to work but I can't figure out how to manually focus an index path without overriding <code>indexPathForPreferredFocusedView</code>. Any advice? Thanks!</p>