我试图在CollectionViewCell类中获取UICollectionViewCell的indexPath。我为此创建了一个扩展,但返回nil
我尝试了这段代码
extension UICollectionViewCell{
var collectionView:UICollectionView?{
return superview as? UICollectionView
}
var indexPath:IndexPath?{
return collectionView?.indexPath(for: self)
}
}
它为superview as? UICollectionView
返回nil