pre select/highlight UICollectionViewCell on first load of view

后端 未结 9 1252
醉酒成梦
醉酒成梦 2021-02-07 05:48

Im trying to preselect the first object/UICollectionViewCell in the UICollectionView? I have tried:

self.dateCollectionView.allowsMultipleSelection=NO;

[self.da         


        
9条回答
  •  执笔经年
    2021-02-07 06:11

    For me, putting it in viewDidAppear: cause a second to select, so the user will see both states (i.e. not selected, and selected). To avoid this, I put it in viewWillAppear: instead and worked like a charm

    override func viewWillAppear(_ animated: Bool) {
        let selectedIndexPath = IndexPath(item: 0, section: 0)
        collectionView.selectItem(at: selectedIndexPath, animated: false, scrollPosition: .left)
    }
    

提交回复
热议问题