1

I am trying to segue an array of images from a UICollectionViewController to a UITableViewController with static cells. The setup is that when a user presses a cell in the collection view controller, the UIImage in that cell segues to the UIImageView in the table view controller.

The problem is that the image is not appearing in the UITableViewController's UIImageView.

I think that the UIImage is not being passed to the UIImageView in the UITableViewController.

Here is my relevant UICollectionViewController code:

import UIKit

private let reuseIdentifier = "Cell"

class AddImageCollectionViewController: UICollectionViewController {

var mainImages = ["cup", "transport", "beach", "weather", "gear", "money", "technology-1", "web", "people", "nature", "draw", "technology", "screen", "shop", "arrow"]

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: UICollectionViewDataSource

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of items
    return mainImages.count
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

    let screenSize = UIScreen.mainScreen().bounds
    let screenWidth = screenSize.width / 3
    let screenHeight = screenWidth

    let size = CGSize(width: screenWidth, height: screenHeight)

    return size
}

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

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! AddImageCollectionViewCell


    // Configure the cell
    cell.mainImageView.image = UIImage(named: mainImages[indexPath.row])

    return cell
}

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    collectionView?.reloadData()
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "nextStep" {
        if let indexPaths = collectionView?.indexPathsForSelectedItems() {
            let destinationViewController = segue.destinationViewController as! AddTableViewController
            //let photoViewController = destinationViewController.viewControllers[0] as! PhotoViewController
            destinationViewController.imageName = mainImages[indexPaths[0].row]
        }
    }
}
}

Here is my relevant UITableViewController code:

import UIKit
import CoreData

class AddTableViewController: UITableViewController {

// MARK: - Table view data source

@IBOutlet var photoImageView:UIImageView!

var content:Agenda!
var imageName:String = ""

override func viewDidLoad() {
    super.viewDidLoad()

    photoImageView.image = UIImage(named: imageName)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

After selecting my cell in the Collection View Controller in the simulator, I get the following error message in the console:

CUICatalog: Invalid asset name supplied:

Annabelle Sykes
  • 263
  • 6
  • 17

0 Answers0