此代码用于在swift 2.3和更早版本中工作。但是当我在Swift 3中更新它时,应用程序崩溃了。layoutAttributesForElementsInRect Swift 3(UICollectionView)
这是SWIFT 2.3
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]?
{
var layoutAttributes = [UICollectionViewLayoutAttributes]()
layoutInfo?.enumerateKeysAndObjectsUsingBlock({ (object: AnyObject, elementInfo: AnyObject, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let infoDic = elementInfo as! NSDictionary as NSDictionary!
infoDic.enumerateKeysAndObjectsUsingBlock({ (object: AnyObject!, attributes: AnyObject!, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let attr = attributes as! UICollectionViewLayoutAttributes
if (CGRectIntersectsRect(rect, attributes.frame))
{
layoutAttributes.append(attr)
}
})
})
return layoutAttributes
}
的代码,这是更新版本雨燕3
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes = [UICollectionViewLayoutAttributes]()
layoutInfo?.enumerateKeysAndObjects({ (object: AnyObject, elementInfo: AnyObject, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let infoDic = elementInfo as! NSDictionary as NSDictionary!
infoDic?.enumerateKeysAndObjects({ (object: AnyObject!, attributes: AnyObject!, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let attr = attributes as! UICollectionViewLayoutAttributes
if (rect.intersects(attributes.frame))
{
layoutAttributes.append(attr)
}
} as! (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Void)
} as! (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Void)
return layoutAttributes
}
我得到这个崩溃在}作为! (Any,Any,UnsafeMutablePointer) - > Void)EXC_BREAKPOINT
任何人都可以帮我吗?
这是我从这个家伙拿来的项目。 https://github.com/CoderXpert/EPGGrid
是的,他们是字典..有一种方法,我可以用我的layoutInfo和infoDic填充缓存? – jboisjoli