Im trying to preselect the first object/UICollectionViewCell in the UICollectionView? I have tried:
self.dateCollectionView.allowsMultipleSelection=NO;
[self.da
I solved this by subclassing UICollectionView
and selecting needed item in layoutSubviews
:
class InitialSelectionCollectionView: UICollectionView {
var initialSetupPerformed: Bool = false
var initialSelectedIndexPath: IndexPath!
override func layoutSubviews() {
super.layoutSubviews()
if !initialSetupPerformed && initialSelectedIndex != nil{
selectItem(at: initialSelectedIndexPath, animated: false, scrollPosition: .centeredHorizontally)
initialSetupPerformed = true
}
}
}
Then, when you init your custom collection view, just set needed IndexPath
to initialSelectedIndexPath