Select items programmatically in UICollectionView

后端 未结 4 974
小鲜肉
小鲜肉 2020-12-09 17:27

I have a UICollectionViewController:

- (NSInteger)collectionView:(UICollectionView *)collectionView 
     numberOfItemsInSection:(NSInteger)sect         


        
4条回答
  •  旧巷少年郎
    2020-12-09 18:14

    For right behaviour call 4 function in a row:

    // Deselect
    self.collection.deselectItem(at: previousPath, animated: true)
    self.collectionView(self.collection, didDeselectItemAt: previousPath)
    
    // Select
    self.collection.selectItem(at: path, animated: true, scrollPosition: .centeredVertically)
    self.collectionView(self.collection, didSelectItemAt: path)
    

提交回复
热议问题