我使用UICollectionView
,在滾動的UICollectionView
特定部分我在寫UICollectionView
的擴展,它工作正常在iPhone 6 &還對模擬器但在iPhone 5應用程序得到墜毀我調試,但無法找到問題所在。應用越來越墜毀,機上`layoutAttributesForSupplementaryElement`
這裏是我的代碼
extension UICollectionView {
func scrollToIndexpathByShowingHeader(_ indexPath: IndexPath) {
let sections = self.numberOfSections
if indexPath.section <= sections {
let attributes = layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath)
let topOfHeader = CGPoint(x: 0, y: attributes!.frame.origin.y - self.contentInset.top)
self.setContentOffset(topOfHeader, animated:false)
}
}
}
上let attributes = layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath)
我的應用程序得到墜毀,墜毀的原因是:
reason: 'no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind: UICollectionElementKindSectionHeader at path <NSIndexPath: 0x1564e0b0> {length = 2, path = 18 - 1}'
請讓我知道什麼是問題,以及如何解決 在此先感謝:-)
我不明白這一點。請多說一些。 @Jaydeep –
上一個答案是正確的'layoutAttributesForItem(at:indexPath)'好心地重新編輯,以便我可以發現 –
@asimabbasi,奇怪:) – Jaydeep