我试图创建一个图像的集合视图。我尝试了这些解决方案,下载图片:
和
var tempObject = json["photos"]
for var i = 0; i < tempObject.count; i++
{
var tempImage = UIImage()
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
在swift中遇到了问题。我在“Products.swift”类中有一个“products”数组,当我尝试将“products”数组访问到“SortLauncher.swift”类中时,它返回“nil”。
Products.swift
import Apollo
class Products: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchBarDelegate {
var products: [ProductsQuery.Data.Node
我用的是sizeForItemAt indexPath和UICollectionView。
当我提交一个动作从collectionView和dataSource数组中删除一个项时,我调用reloadData。然而,在sizeForItem中,我得到了一个Fatal error: Index out of range。
dataSource计数是正确的,并反映了变化。例如,从4项到3项。indexPath是sizeForItem试图访问的第四个索引0 - 3。
我为什么要犯这个错误?sizeForItem运行在cellForItem或numberOfItemsInSection之前重要吗?
删除
在我当前的项目中,我将一个NSFetchedResultsController与一个工作良好的UICollectionView集成在一起。目前,我尝试将项目升级到Swift 3和Xcode 8,这会导致以下错误消息
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread.
我使用一个BlockOperation数组来排队对UICollectionView的更改。下面是我如何插入一个新项目的一个例子