pre select/highlight UICollectionViewCell on first load of view

后端 未结 9 1371
醉酒成梦
醉酒成梦 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 05:53

    For Swift 3.0.1 You can try this:

    self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
    

    or

    self.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: UICollectionViewScrollPosition(rawValue: 0))
    

    For Objective-C You can try this:

    self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
    

    Note: You should use it in viewDidAppear

提交回复
热议问题