- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用UICollectionView
,滚动到 UICollectionView
的特定部分时我在 UICollectionView
上写了一个扩展这在 iPhone 6 和模拟器上运行良好,但在 iPhone 5 应用程序中崩溃了,我对其进行了调试,但无法找到问题所在。
这是我的代码
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}'
请让我知道问题是什么以及如何解决预先感谢:-)
最佳答案
这是因为单元格无法检索layoutAttributes。如果更新创建的单元格不可见,则layoutAttributesForItemAtIndexPath返回nil。
我认为以下解决方案适合您。
重写layoutAttributesForItemAtIndexPath必须使用此方法:
swift 3.0对于 header 方法,希望对您有帮助
override func layoutAttributesForItemscrollToSection(at_ indexPathsection: IndexPathInt) -> UICollectionViewLayoutAttributes? {
//set Contentoffset to particular section
}
关于swift - 应用程序在 `layoutAttributesForSupplementaryElement` 处崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45100623/
我正在使用UICollectionView ,滚动到 UICollectionView 的特定部分时我在 UICollectionView 上写了一个扩展这在 iPhone 6 和模拟器上运行良好,但
我是一名优秀的程序员,十分优秀!