There are many other topics of passing data to another ViewController - i know - but i could not find the solution for passing data from UITableViewCell to UIViewController. The question differs from others that here i have to access an ImageView in another class of UITableViewCell. Segues, prepare for segues an other topics are discussed in other posts sufficiently but not this special constellation.
I have a class UITableViewCell:
class PostCell: UITableViewCell {
...
// networkService is downloading an image
networkService.downloadImage({ (imageData) in
let image = UIImage(data: imageData as Data)
...
// image is set to UIImageView
self.postImageView.image = image
In my ViewController i do this to go to the DetailViewController:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
aktIndex = indexPath.section
performSegue(withIdentifier: "segueDetail", sender: self)
}
I tried this:
let MainStory:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let desVC = MainStory.instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
desVC.getImage = ???
self.navigationController?.pushViewController(desVC, animated: true)
DetailViewController:
class DetailViewController: UIViewController {
var getImage = UIImage()
...
I have made a segue in xcode (segueDetail):
At the moment i store the imagedata in UserDefaults and read them again in the DetailViewController. Very weird, i know.
Where do i have to pass the data from? In my PostCell or in the ViewController? The problem is to get access to image-data from PostCell in my ViewController.