TL; DR:第一次显示包含集合视图的单元格时autolayout引擎计算的高度总是错误的.调用reloadData()表视图可以解决问题,但也会使表视图跳转并无法使用.任何的想法?
解释:我有一个表视图,其中包含许多不同高度的不同单元格.
其中一个单元格是一个图像库,可以包含一个或多个异步加载的图像.
我有的限制如下:
我面临的问题如下:
当表视图第一次尝试显示图库单元格时,我收到了Super Annoying Encapsulated-Height-Layout问题.即使已更新集合视图上的高度约束,此封装高度始终具有错误值.
表格视图在第一次尝试时始终无法正确获取单元格的大小.
我正在使用Kingfisher来检索图像,这里是代码:
UICollectionViewCell数据源:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CarouselCollectionViewCell", forIndexPath: indexPath) as! CarouselCollectionViewCell
guard let collectionView = collectionView as? CarouselCollectionView else { return cell }
if let imagesURLs = data.imagesURLs {
let url = imagesURLs[indexPath.item]
if let smallURL = url.small {
KingfisherManager.sharedManager.retrieveImageWithURL(
smallURL,
optionsInfo: KingfisherOptionsInfo(),
progressBlock: nil,
completionHandler: { (image, error, cacheType, imageURL) -> () …Run Code Online (Sandbox Code Playgroud)