【发布时间】:2015-05-05 18:06:00
【问题描述】:
我已经尝试通过使用 uicollectionview 的扩展来获取集合视图中心单元格的索引,但我总是得到 nil 而不是索引。我该如何解决这个问题?
extension UICollectionView {
var centerPoint : CGPoint {
get {
return CGPoint(x: self.center.x + self.contentOffset.x, y: self.center.y + self.contentOffset.y);
}
}
var centerCellIndexPath: NSIndexPath? {
if let centerIndexPath: NSIndexPath = self.indexPathForItemAtPoint(self.centerPoint) {
return centerIndexPath
}
return nil
}
}
然后:在随机方法中的 UIViewController 中我有这个:
if let centerCellIndexPath: NSIndexPath = collectionTemp!.centerCellIndexPath {
print(centerCellIndexPath)
} else {
println("nil")
}
索引路径总是为零,我不明白为什么,因为单元格按顺序显示,除此之外一切都很好。
【问题讨论】:
-
这方面有什么更新吗?
标签: ios swift uicollectionview uicollectionviewcell nsindexpath