Ios 如何禁用UICollectionViewCell';当UIImageView.image仍然为空时,s用户交互

Ios 如何禁用UICollectionViewCell';当UIImageView.image仍然为空时,s用户交互,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,当imageView仍然为空时,是否可以将UICollectionViewCell的userInteractionEnabled设置为false,或者不让tpperformsegue进入详细视图?我试着去做,但没用。下面是示例方法: func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

imageView
仍然为空时,是否可以将
UICollectionViewCell
userInteractionEnabled
设置为
false
,或者不让tp
performsegue
进入详细视图?我试着去做,但没用。下面是示例方法:

 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CustomCollectionViewCell
            dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {


                cell.userInteractionEnabled = false
                cell.products.image = UIImage(named: "placeholderImage")
                cell.activityIndicator.startAnimating()
                let p = self.products[indexPath.row] as Product

                if let img = UIImage(data: p.productImage) {
                    cell.products.image = img
                }
                else {

                    self.loadImages(p, indexPath: indexPath)
                }

                dispatch_async(dispatch_get_main_queue()) {
                    // update some UI

                    cell.activityIndicator.stopAnimating()
                    cell.userInteractionEnabled = true

                }

            }



    return cell
}

我认为您不正确地使用了
调度同步(调度获取全局队列(调度队列优先级默认为0))
。您正在将UI更新放入其中(即启动微调器动画),这是错误的。据我所知,您希望进行异步映像加载的代码,以及我明确建议使用的代码 这样做。这是一个很好的库,可以进行很好的异步映像加载


只要使用它并将所有代码放在主线程中,就不需要使用任何dispatch\u async

loadImages做什么?它从下面的comletionHandler块中的url加载图像;让taskData=session.dataTaskWithRequest(请求,completionHandler:{(数据:NSData?,响应:NSURLResponse?,错误:NSError?)->Void选中我的答案,看看是否合适。如果不合适,我们必须查看loadImages方法。首先,我放置了一个占位符图像,然后从url加载产品图像。我只是不想调用故事板序列号(单击单元格时)并在加载产品照片之前转到详细视图。因为如果在加载真实图像之前单击collectioncell,它将显示空图像视图。我应该将cell的userinteractiveenable属性禁用为false,或者在详细视图的did load方法中加载图像(如果未加载)。@MehmetTa请按照我回答中的步骤进行操作,并尝试这样做。它应该是认真考虑使用SDWebI图,你应该添加代码以使它在下载完成时被启用(下载完成回调)。这将使它如您所期望的那样工作。是的,您是对的,我将UI更新放在dispatch_sync块内,但这是错误的。在我将有关准备单元格的代码放在块外后,它工作得很好。谢谢。