UICollectionView current visible cell index

后端 未结 16 1427
难免孤独
难免孤独 2020-11-29 16:52

I am using UICollectionView first time in my iPad application. I have set UICollectionView such that its size and cell size is same, means only onc

16条回答
  •  抹茶落季
    2020-11-29 17:18

    It will probably be best to use UICollectionViewDelegate methods: (Swift 3)

    // Called before the cell is displayed    
    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        print(indexPath.row)
    }
    
    // Called when the cell is displayed
    func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        print(indexPath.row)
    }
    

提交回复
热议问题