0

This might end up being a really simple thing but I've been pondering over it for half and hour.

I have an Image View on a View Controller. From there I Modal to a Collection View with Images. I want to select an image from the Collection View and have it show up on the Image View on the first View Controller.

I can get to Collection View and get the indexPath but can't figure out what to do next.

class ImageCollectionViewController: UIViewController, UICollectionViewDelegate,UICollectionViewDataSource {

func collectionView(collectionView: UICollectionView!, didSelectItemAtIndexPath indexPath: NSIndexPath!) {
        self.dismissModalViewControllerAnimated(true)

}
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
GgnDpSingh
  • 1,737
  • 2
  • 12
  • 11

2 Answers2

0

You may create a delegate for your modal controller and implement it in the parent view controller. Just remind to assign modal controller delegate in the prepareForSegue implementation. I wrote an article on protocol and delegation in Swift, you can read it here to get any help.

sweepy_
  • 1,333
  • 1
  • 9
  • 28
  • I can handle all that. What I can't understand is that I have the indexPath of the image which is an integer. How do I get the actual Image to show from the indexPath inside didSelectItemAtIndexPath? – GgnDpSingh Jun 12 '14 at 17:42
0

I think this is what you're looking for. It worked for me:

    func collectionView(collectionView: UICollectionView!, didSelectItemAtIndexPath indexPath: NSIndexPath!) {

    var yourIndexPath = indexPath
    var selectedCell = collectionView.cellForItemAtIndexPath(yourIndexPath) as ArchiveCells
    var imageInCell = selectedCell.yourCellImageName.image

    //whatever else you need to do
    self.dismissModalViewControllerAnimated(true)
}
Melly
  • 675
  • 5
  • 6