pre select/highlight UICollectionViewCell on first load of view

后端 未结 9 1264
醉酒成梦
醉酒成梦 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:00

    For Swift 3:

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        //auto selected 1st item
        let indexPathForFirstRow = IndexPath(row: 0, section: 0)
        self.collectionView?.selectItem(at: indexPathForFirstRow, animated: true, scrollPosition: .top)
    }
    

提交回复
热议问题