Post

Replies

Boosts

Views

Activity

Reply to iOS 14 UICollectionView scrollToItem not working
My working solution (hack) is to introduce an empty cell that gets returned when we are initially scrolling. `class EmptyVideoCellBeforeScrollingCollectionCell: UICollectionViewCell {   static let ID = "EmptyVideoCellBeforeScrollingCollectionCell" } var scrollToIndex: IndexPath?      let dataSource = HashableDataSource(collectionView: collectionView) { [weak self] (collectionView, indexPath, item) -> UICollectionViewCell? in       guard let self = self else { return nil }                 if let idx = self.scrollToIndex{         if idx != indexPath{           if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: EmptyVideoCellBeforeScrollingCollectionCell.ID, for: indexPath) as? EmptyVideoCellBeforeScrollingCollectionCell {             return cell           }         }       }   override func viewWillAppear(_ animated: Bool) {     super.viewWillAppear(animated)          if let idx = self.scrollToIndex{       self.feedCollectionView.scrollToItem(at: idx, at: .top, animated: false)       self.scrollToIndex = nil     }         }`
Jun ’21