0

I currently have a UICollectionView embed within a UICollectionViewCell, labels within the embbed the embbedViewController work properly but there's a problem with the UIImageView. For some strange reason I'm unable to set images from URL using AlamofireImage or Haneke but works properly when the image is set from a UIImage in Image.xcassetts. Would anyone be able to shed some light as to why this is happening?

embbedCollectionView

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("trendCell", forIndexPath: indexPath) as! customCollectionViewCell let imgUrl = NSURL(fileURLWithPath: mainViewArrayContainer.artImg[indexPath.row]) cell.secondCollectionViewImage.hnk_setImageFromURL(imgUrl) cell.secondCollectionViewLabel.text = mainViewArrayContainer.artImg[indexPath.row] return cell } 

ParentViewController

 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { if (indexPath.row == 3){ let cell = collectionView.dequeueReusableCellWithReuseIdentifier("trendingCell", forIndexPath: indexPath) as! customCollectionViewCell let controller:EmbbedCollectionViewController = self.storyboard!.instantiateViewControllerWithIdentifier("embbedCollectionView") as! EmbbedCollectionViewController addChildViewController(controller) cell.addSubview(controller.view) return cell } else{ //removed to save space } 
1
  • Update your question with relevant code. Commented Nov 13, 2015 at 3:41

1 Answer 1

1

For some strange reason I'm unable to set images from URL using AlamofireImage or Haneke

You cannot set the image directly by downloading. You must return the cell now. Downloading takes time. You have to download asynchronously and go back and set the image later.

Sign up to request clarification or add additional context in comments.

3 Comments

also, when finish fetching images from asynchronous block, remember to ensure you are setting the images in a main queue.
That makes sense, thank you. How can i ensure the images are being set in the main queue? @MatthewLuiHK
Just force to do it by using : dispatch_sync(dispatch_get_main_queue()) { () -> Void in }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.