简体   繁体   中英

Can't feed imageView from a selected image in a tableView or collectionView into a detailView

I'm going from a collection or tableView and either one that I choose, it won't appear in the detail controller.

These are the errors I get:

Here is the code in the detailViewController:

var meme = SentMemeImageView.self

@IBOutlet weak var sentMemesBtn: UIBarButtonItem!
@IBOutlet weak var editBtn: UIBarButtonItem!
@IBOutlet weak var sentMemeView: UIImageView!


override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    displayMeme(meme)

}

override func viewDidLoad() {
    super.viewDidLoad()

}

func displayMeme(_ meme: SentMemeImageView) {

    sentMemeView.image = meme.memedImage

}

@IBAction func launchMemeEditorViewController(_ sender: Any) {
    _ = navigationController?.popViewController(animated: true)

}

//unwinding to the view before (the collectionView, or the tableView)

@IBAction func unwindVC(for unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
    self.dismiss(animated: true, completion: nil)
}

}

I need to call the memedImage , but from the struct MemeImage I was unable to call just the memedImage so I made another struct with just that, however I cannot call it to the detail view controller without those error's popping up.

struct MemeImage {
    let topText: String
    let bottomText: String
    let originalImage: UIImage
    let memedImage: UIImage
}


struct SentMemeImageView {
    let memedImage: UIImage
}

Thanks.


Update: AppDelegate

import UIKit
import CoreData

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {

        var window: UIWindow?
        var memes = [MemeImage]()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
            return true
   }

In your TableViewController in the prepareForSegue you need to tell it what data to pass to the detailViewController.

var myData: [NSManagedObject] = []

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        let selectedIndexPath:NSIndexPath = self.tableView.indexPathForSelectedRow!
        let vc = segue.destinationViewController as! detailViewController

        vc. meme = myData[selectedIndexPath.row]

}

Then in the detail viewDetailViewController.

@IBOutlet weak var memeView: UIImageView!
var meme: NSManagedObject?  // You will use this for the index when pulling the image from how ever you are storing it. 

// The memeImage will need to be set from how ever you are storing the image.
self.memeView.image = UIIamge(named: meme) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM